LET with LOOP construct in Common Lisp

87 views Asked by At

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?

1

There are 1 answers

1
Will Ness On BEST ANSWER

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.