loopscommon-lisplet

LET with LOOP construct in Common Lisp


I have the following code:

(let (liste (loop for item from 1 to 20 collect item))
  (format t "~{~a~}~" liste))

However portacle complains: The variable FOR is unbound. Why?


Solution

  • Given your code, CLISP complains:

    *** - LET: illegal variable specification
           (LOOP FOR ITEM FROM 1 TO 20 COLLECT ITEM)
    

    So the problem is with LET, not with LOOP.

    You are missing an additional pair of parentheses:

    ;;;    v                                               v
    (let ( (liste (loop for item from 1 to 20 collect item)) )
      (format t "~{~a~}~" liste))
    

    This will give you a different error message, concerning the format directive.