Thanks, that is a very cool URL.
I sure could have used Reducers when I implemented the (combinations) function.
To make it efficient, I had to switch from map to dolist to avoid that exact problem that the Reducer functions address.
http://www.newlisp.org/index.cgi?page=Code_Snippets
Code: Select all
(define (combinations n k (r '()))
(if (= (length r) n)
(list (sort r <))
(apply append (map
(fn (x) (combinations n ((+ 1 $idx) k) (cons x r))) k))))
; (combinations 2 '(a b c))
; => ((a b) (a c) (b c))
I'd really like to know how that would look using Reducers instead of dolist. dolist did do the job very efficiently, map blew up my computer.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.