Lazy Mapping

Discussion of Common Lisp
Post Reply
audwinc
Posts: 12
Joined: Thu Sep 02, 2010 11:46 am

Lazy Mapping

Post by audwinc » Fri Sep 03, 2010 1:32 pm

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?

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Lazy Mapping

Post by gugamilare » Fri Sep 03, 2010 4:33 pm

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.

Post Reply