Subject: Re: Maintaining multivariable state (newbie question)
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 25 Aug 2007 20:21:50 -0500
Newsgroups: comp.lang.lisp
Message-ID: <Yc6dnYceUr8zSE3bnZ2dnUVZ_h2pnZ2d@speakeasy.net>
Scott Burson  <FSet.SLB@gmail.com> wrote:
+---------------
| Robert Uhl <eadmun...@NOSPAMgmail.com> wrote:
| > So: (let ((context (copy-context=with-variations +FOO-context+
| >                                                :add-1 t
| >                                                :colour nil)))
| >        (FOO BAR context))
| > is cleaner than:
| >   (let ((*FOO-add-1* t)
| >         (*FOO-colour nil))
| >        (FOO BAR))
...
| () If I ever need to delay some operation by wrapping it in a lambda
| and calling the resulting function later, the first form will behave
| predictably and the second won't.
+---------------

Sure it will, if you wrap the LAMBDA around the binding form too:

    (lambda ()
      (let ((*FOO-add-1* t)
	    (*FOO-colour nil))
        (FOO BAR)))

Or if you're worried about more parameters than those, you could
always do something along these lines [which I confess I have done
on certain rare occasions]:

    (let ((later-add-1 t)
	  (later-colour nil)
	  (later-style *foo-style*)
	  (later-font *foo-font*)
	  (later-weight *foo-weight*))
      (lambda (bar)
	(let ((*foo-add-1* later-add-1)
	      (*foo-colour* later-colour)
	      (*foo-style* later-style)
	      (*foo-font* later-font)
	      (*foo-weight* later-weight))
	  (foo bar))))


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607