Page 1 of 1

Lazy Mapping

Posted: Fri Sep 03, 2010 1:32 pm
by audwinc
Suppose I define a few functions for handling a poor man's lazy list like this:

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}>)
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?

Re: Lazy Mapping

Posted: Fri Sep 03, 2010 4:33 pm
by gugamilare
You can't use CL functions, you will have to roll your own. What you are trying to do has already been done, though, take a look at Series and see if it fits your purpose.