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)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 362 |
Nodes: | 16 (2 / 14) |
Uptime: | 32:12:43 |
Calls: | 7,732 |
Files: | 12,873 |
Messages: | 5,731,053 |