[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SOME (and other mapping functions)
- To: info-mcl@ministry.cambridge.apple.com
 
- Subject: SOME (and other mapping functions)
 
- From: pazzani@pan.ICS.UCI.EDU (Michael Pazzani)
 
- Date: 4 Jan 94 17:15:18 GMT
 
- Newsgroups: comp.lang.lisp.mcl
 
I prefer to use mapping functions when possible instead of do or loop.
However, it appears that I pay a penalty for my stylistic preference
because when using some lambda expressions as the function argument
(e.g., one that references a lexical variable other than the parameter)
space gets allocated.
(defun greater-some (x list)
    (some #'(lambda(e)(> e x)) list))
(time (greater-some 7 '(1 2 3 4 5 6 7 8)))
(GREATER-SOME 7 '(1 2 3 4 5 6 7 8)) took 0 milliseconds (0.000 seconds) to run.
 40 bytes of memory allocated.
T
Is there any declaration, etc that can avoid this spoce allocation.  Neither
do or loop allocate any space:
(defun greater-do(x list)
    (do ((l list (cdr l)))
        ((or (null l)
             (> (car l) x))
         (not (null l)))))
(defun greater-loop(x list)
    (loop for e in list
          when (> x e)
          return t))
? (time (greater-do 7 '(1 2 3 4 5 6 7 8)))
(GREATER-DO 7 '(1 2 3 4 5 6 7 8)) took 0 milliseconds (0.000 seconds) to run.
T
? (time (greater-loop 7 '(1 2 3 4 5 6 7 8)))
(GREATER-LOOP 7 '(1 2 3 4 5 6 7 8)) took 0 milliseconds (0.000 seconds) to run.
T
Thanks
Mike
Michael Pazzani
Department of Information and Computer Science
University of California
Irvine, CA 92717-3425
phone (714) 856-5888
fax   (714) 856-4056
e-mail pazzani@ics.uci.edu