Frege / frege-repl

Frege REPL
78 stars 17 forks source link

Amount of output #22

Closed Ingo60 closed 9 years ago

Ingo60 commented 9 years ago

List output is truncated, which is a good thing in case someone tries to print an infinite list.

frege> iterate (*2) 3.14
[3.14,6.28,12.56,25.12,50.24,100.48,200.96,401.92,803.84,1607.68,3215.36,6430.72

However, it is not transparent what the limit is (characters? list elements?) and, above all, it is not configurable. Hence I propose something like:

:set listmax 30

which would make the REPL print 30 list elements.

I understand it is hard, because there may be a finite list or something that has infinite sublists. But this seems to fail also today, try

frege> Just $ iterate (*3) 3.14

Perhaps a character limit is in order, to make things not too complex. But also this limit should be configurable.

Ingo60 commented 9 years ago

I just recoginze, that the derived instances for Show may be broken with respect to showChars. Will try to fix this.

mmhelloworld commented 9 years ago

This is what the REPL is doing to print an expression (if it is "showable"):

packed . take 80 . showChars $ expr

The limit should definitely be configurable. I will fix this. How about the configuration key showlimit instead of listmax since listmax seems bit too general.

mmhelloworld commented 9 years ago

A new option show-limit is now available to control the the amount of output.

frege> [1..]
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,3

frege> :set show-limit 30

frege> [1..]
[1,2,3,4,5,6,7,8,9,10,11,12,13

frege> :set show-limit 100

frege> [1..]
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
Ingo60 commented 9 years ago

Great!

One thought for future development: With lists, one sees immediately that the output has been cut. Not necessarily so with other data types. For example, in the ever re-occuring fibonacci examples, very large numbers are resulting very quickly, and it is often not immediately clear whether one sees the whole number or just a part of it. Therefore, an indication at the end of the cut output would be great, like a (possibly visually emphasized) ... Even better would it be when there was a key hat would result in printing of the next portion. One possibility that comes to mind is an empty line. Whenever there is a previous value that has been cut, just hitting "Enter" could print the next portion, and so on. Should not be too hard to implement, would it?