diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-10-06 06:37:40 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-10-06 12:24:27 -0700 |
commit | 5698af7271b5c21a4b8a2721e5c20f66ad0dd7e2 (patch) | |
tree | e02708f59a219d6ec5cdfbbd0828b33745b75074 /txr.1 | |
parent | 037e9a2b91f982fc941af8a152b4b104e418755b (diff) | |
download | txr-5698af7271b5c21a4b8a2721e5c20f66ad0dd7e2.tar.gz txr-5698af7271b5c21a4b8a2721e5c20f66ad0dd7e2.tar.bz2 txr-5698af7271b5c21a4b8a2721e5c20f66ad0dd7e2.zip |
New function, expand-right.
* eval.c (expand_right_fun, expand_right): New static
functions.
(eval_init): Register expand-right intrinsic.
* txr.1: Documented expand-right.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 72 |
1 files changed, 72 insertions, 0 deletions
@@ -15837,6 +15837,78 @@ then the list is terminated, and no more items are produced. (ginterate (op > 5) (op + 1) 0) -> (0 1 2 3 4 5) .cble +.coNP Function @ expand-right +.synb +.mets (expand-right < gen-fun << value ) +.syne +.desc +The +.code expand-right +is a complement to +.codn reduce-right , +with lazy semantics. + +The +.meta gen-fun +parameter is a function, which must accept a single argument, +and return either a cons pair +or +.codn nil . + +The +.meta value +parameter is any value. + +The first call to +.meta gen-fun +receives +.metn value . + +The return value is interpreted as follows. If +.meta gen-fun +returns a cons cell pair +.cblk +.meti >> ( elem . << next ) +.cble +then +.meta elem +specifies the element to be added to the lazy list, +and +.meta next +specifies the value to be passed to the next call +to +.metn gen-fun . +If +.meta gen-fun +returns +.code nil +then the lazy list ends. + +.TP* Examples: + +.cblk + ;; Count down from 5 to 1 using explicit lambda + ;; for gen-fun: + + (expand-right + (lambda (item) + (if (zerop item) nil + (cons item (pred item)))) + 5) + --> (5 4 3 2 1) + + ;; Using functional combinators: + [expand-right [iff zerop nilf [callf cons identity pred]] 5] + --> (5 4 3 2 1) + + ;; Include zero: + [expand-right + [iff null + nilf + [callf cons identity [iff zerop nilf pred]]] 5] + --> (5 4 3 2 1 0) +.cble + .coNP Function @ repeat .synb .mets (repeat < list <> [ count ]) |