Subject: Re: Road to Special Enlightenment Survey
From: rpw3@rpw3.org (Rob Warnock)
Date: Mon, 23 Feb 2009 22:02:21 -0600
Newsgroups: comp.lang.lisp
Message-ID: <yq6dncJPKq7Q7D7UnZ2dnUVZ_qzinZ2d@speakeasy.net>
Kenneth Tilton  <kentilton@gmail.com> wrote:
+---------------
| Raise your hand if you learned how specials work when some other Lisper 
| straightened you out after seeing this code of yours:
| 
|    (let ((save *grafport*))
|        (setf *grafport* myport)
|        (..some grafporting code..)
|        (setf *grafport* save))
| 
| ...with this:
| 
|    (let ((*grafport* myport))
|       (..some grafporting code..))
| 
| If so, how much Lisp had you written by then?
| 
| Raise your other hand if you just found out.
+---------------

For even more extra credit(?!?), raise your third hand if you
already knew about the second form above but just now found out
that you can do the same thing this way:

    (defun do-some-grafporting-thingy (&optional (*grafport* *grafport*))
      ...some grafporting code...)

    ...
    (do-some-grafporting-thingy)	; Uses current value of *GRAFPORT*
    ...
    (do-some-grafporting-thingy myport)	; Temp binds *GRAFPORT* to MYPORT
    ...


-Rob

p.s. A very common usage of that is this idiom:

    (defun format-val (val &key ((stream *standard-output*) *standard-output*))
      (format t "...{magic format for a VAL}..." val))

followed by:

    (format-val some-val)	; goes to *standard-output*
or:
    (format-val some-val :stream some-other-stream-entirely)

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