Hi all,
a Happy New Year!! :)
As a kind of New-Year's present, 64-bit PicoLisp received a new feature
(with version 3.1.9.2):
A destructuring 'let'
That means that in addition to the normal 'let' calls with a single
symbol/value pair
(let A 1
.. )
or a list of symbol/value pairs
(let (A 1 B 2 C 3)
.. )
pil64 now also supports nested structures of symbols:
(let ((A . Z) (1 2 3 4))
(list A Z) )
-> (1 (2 3 4))
(let (X 3 ((A . B) (C D) E . F) '((1 2 3) (4 5 6) 7 8 9) Y 4)
(list X A B C D E F Y) )
-> (3 1 (2 3) 4 5 7 (8 9) 4)
(let (((A . B) (C) . D) '((1 2 3) (4 5 6) 7 8 9))
(list A B C D) )
-> (1 (2 3) 4 (7 8 9))
You could achieve a similar goal with 'use' and 'match'
(use (@A @B @C @D)
(and
(match '((@A . @B) (@C . @) . @D) '((1 2 3) (4 5 6) 7 8 9))
(list (car @A) @B (car @C) @D) ) )
-> (1 (2 3) 4 (7 8 9))
but that's quite tedious and ugly.
You can use '@' as a placeholder to ignore parts of a pattern:
(let (((A . @) @ @ D) '((1 2 3) (4 5 6) 7 8 9))
(trail T) )
-> (A 1 D 8)
'@' is not bound to the matching values and thus saves stack space.
I hope this is useful.
♪♫ Alex
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe