chickadee » ck-macros » c-fold1

(c-fold1 '(OP ...) INIT L) → resultsyntax

Yield a value by repeatedly calling the quoted operation with each item from the list and the previous result.

If the list is empty, yields INIT. Otherwise, the operation is first called with two arguments: the first item of the list, and INIT. Then, the operation is repeatedly called with the next item of the list and the previous result, until it reaches the end of the list. Yields the final result.

Analogous to fold from SRFI 1, but only accepts one list. Prior to version 0.2.0, this was named c-fold.

(ck () (c-quote (c-fold1 '(c-cons) '(x) '())))
;; ==> '(x)
(ck () (c-quote (c-fold1 '(c-cons) '(x) '(a b c d e f))))
;; ==> '(f e d c b a x)