Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (1 / 5) |
Uptime: | 45:47:00 |
Calls: | 422 |
Calls today: | 1 |
Files: | 1,024 |
Messages: | 90,336 |
Johan wrote:
I want to map over a list, but to treat the first object differently
from the rest. My previous experience with Lisp was Interlisp, which
has dynamic binding. In Interlisp I could code my problem similar to
this:
(defun foo ()
(let ((first-time t))
(mapcar #'bar '(1 2))))
(defun bar (n)
(cond
(first-time
(setf first-time nil)
(+ n 1))
(t (+ n 2))))
and (foo) would return (2 4). This doesn't work with lexical binding,
and I don't want to make first-time a global variable. What is the
best design pattern in Common Lisp?
(loop for n in '(1 2)
for x = (+ n 1) then (+ n 2)
collect x)