"unfold" for common lisp?

common-lisp, fold, lisp, reduce, scheme

Solution

Common Lisp has `(loop ... collect ...)`. Compare

(loop for x from 1 to 10 collect (* x x))

with its equivalence using `unfold`:

(unfold (lambda (x) (> x 10))
  (lambda (x) (* x x))
  (lambda (x) (+ x 1))
  1)

In general, `(unfold p f g seed)` is basically

(loop for x = seed then (g x) until (p x) collect (f x))

Edit: fix typo

Problem

I learned quite a bit of scheme from SICP but am more interested in common lisp now. I know common lisp's `fold` is `reduce`, with special arguments for left or right folding, but what is the equivalent of `unfold`? Googling has not helped much. In fact I get the impression there is no unfold???

Original source