This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Lazy Mapping

2 posts · 772 views

Suppose I define a few functions for handling a poor man's lazy list like this:
(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

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.