Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does append work in Common Lisp?

I just started learning Lisp and I don't seem to understand the following piece of code:

(setf y (loop for x in y
              for z = (something)
              unless (condition for z)
              append z))

Where is z appended?

like image 682
adrianp Avatar asked Nov 07 '10 13:11

adrianp


1 Answers

It is appended to an unnamed list to be returned when the loop terminates. As first approximation, you may think of it as a shorthand for

(loop ... append z into result finally (return result))

The append here is a loop keyword; it's not related to the append function, except for sharing the same name --- so it's the loop macro that decides how it works, instead of the append function.

like image 124
huaiyuan Avatar answered Oct 03 '22 14:10

huaiyuan