Some time ago we talked in this thread about pretty printing.
I think I should explain this a bit better.
On Wed, Dec 18, 2019 at 12:50:55PM -0800, C K Kashyap wrote:
> (<row> (alternating)
> (gui 1 '(+InsRowButton))
> (if (let L (: chart 1 data) (and (car (nth L R)) (= "ABC" (get
> @ 'cmt)))) (gui 2 '(+TextField) 50 3) (gui 2 '(+TextField) 150 3))
> (gui 3 '(+DateField))
I find this nearly impossible to read. In my reply I edited the last three lines
to
> (if
> (let L (: chart 1 data)
> (and
> (car (nth L R))
> (= "ABC" (get @ 'cmt)) ) )
> (gui 2 '(+TextField) 50 3)
> (gui 2 '(+TextField) 150 3) )
But what are the rules?
PicoLisp uses the most simple algorithm:
1. If the 'size' is 12 or less, print it
2. Otherwise print an opening parenthesis and the CAR, then recursively print
all elements in the CDR each on a new line and indented by 3 spaces. Then
print a space and a closing parenthesis.
In code this is
(de pretty (X N)
(space (default N 0))
(if (or (atom X) (>= 12 (size X)))
(print X)
(prin "(")
(print (car X))
(for Y (cdr X)
(prinl)
(pretty Y (+ N 3)) )
(prin " )") )
X )
The real 'pretty' and 'pp' functions in @lib.l do the same basically, just
employ some heuristics for built-in functions to print the first two or three
items instead of just the CAR.
For non-built-in functions like such GUI code we are free to put more stuff in a
line according to taste, because otherwise it expands vertically too much.
☺/ A!ex
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe