[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hierarchical lists, again



Forgive me if this has already been discussed to death, but I do have
the impression that a concensus has not been reached on the subject of
whether or not to add hierarchical lists to the es language.

As I come from a scheme world myself, my first impulse was that "yes,
certainly I want hierarchical lists".  But now, I think I changed my
mind.  I have come to appreciate the automatic flattening of lists as
one of the conveniences of the es language:  If $x and $y are lists
then ($x $y) is their concatenation rather than a two-element list,
etc.  And this seems to be what is most frequently needed in shell
programming.

On the other hand, we sometimes need the ability to pass two or more
lists into a function!  What to do?  Provide a mechanism for wrapping
a list into a single entity, and then unwrapping it again.

Such a capability need not be added to the language.  It is already
there.  Look here.  This function does the wrapping:

; fn % * {$&result {$&result $*}}

And here is an example on its use.

; w= <={let (x=fee fie foe foo; y=, .) {result <={% $x^$y}}}
; echo $#w   # See, a single element only!
1
; echo <=$w  # And this is how we unwrap the list.
fee, fee. fie, fie. foe, foe. foo, foo.
; let (x= <=$w) {echo $#x}  # In case you doubt that it really got unpacked?
8
; 

What could be easier?  Don't bother with adding hierarchical lists, is
my opinion!

- Harald