Lazy Mapping
Posted: Fri Sep 03, 2010 1:32 pm
Suppose I define a few functions for handling a poor man's lazy list like this:
I can write my own recursive map function for using fcar and fcdr. Is there any built-in support for defining how to traverse a provided "list" so that I can use current CL functions? Since my fcar is just a car, would I just temporary change the definition of cdr to be fcdr? What would be the best approach?
Code: Select all
(defun fcar (o)
(car o))
(defun fcdr (o)
(if (null (cdr o))
nil
(funcall (cdr o))))
(defun range (first last)
(cons first
(if (= first last)
nil
#'(lambda () (range (1+ first) last)))))
(range 1 10) => (1 . #<CLOSURE (lambda #) {B367255}>)