XPost: comp.lang.scheme
Pascal Costanza wrote:
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)
Gauche Scheme
(use gauche.parameter)
(define first-time (make-parameter 'unset))
(define (foo)
(parameterize ((first-time #t))
(map bar '(400 500 600))))
(define (bar n)
(cond
((first-time)
(first-time #f)
(+ n 1))
(#t (+ n 2))))
gosh> (foo)
(401 502 602)
gosh> (first-time)
unset
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)