(setq *cont* #'identity)
to set up a global lexical variable, as opposed to the usual global special.
My compiler, Allegro CL, in its infinite wisdom decided I really wanted
*cont* to be special, and so does it for me. Normally, this is convenient,
but not now; the macros really depend on it being lexical.
How do I do this? Portable would be nice, because I'd like the utilities to
run on CMU CL as well.
(BTW, because of the way the macros work, wrapping all the defmacro and
whatnot in a giant let and doing things that way doesn't work. I tried.)
Graham
--
Graham Hughes <th...@treepeople.dyn.ml.org>
http://treepeople.dyn.ml.org/thrag/
PGP Fingerprint: 36 15 AD 83 6D 2F D8 DE EC 87 86 8A A2 79 E7 E6
>
> I'm working my way through _On_Lisp_ (Paul Graham, 1994), and got to
> chapter 20 where he discusses continuation passing macros. Now, I
> understand all about the macros and how they work, but his example
> does a
>
> (setq *cont* #'identity)
>
> to set up a global lexical variable, as opposed to the usual global
> special.
Yeah, I think this is undefined and implementations are free to
interpret it in several different ways. Something like the following
should work. I didn't test it, though. Sorry--you get what you pay
for...
(defmacro deflexical (var &optional init doc)
`(progn (define-symbol-macro ,var (get ',var 'lexical))
(setf ,var ,init)
(setf (get ',var 'lexical-doc) ',doc)
',var))
dave
It's a binding that's something you can close over and is thus not
interfered with by either lexical or special bindings.
That is,
(deflexical x 3)
(defun f () x)
Is the same as
(let ((x 3)) (defun f () x))
except that the scope of the x is global instead of local to a binding form.
So, for example:
(deflexical x 3)
(defun f () x) ;closed over x
(defun g (y)
(let ((x (+ y 1)))
(declare (special x))
(h (+ x 1))))
(defun h (x)
(list (f) (locally (declare (special x)) x) x))
(g x)
=> (3 4 5)
I was in a hurry and didn't test any of the above.
But it loks right to me...
: (setq *cont* #'identity)
: to set up a global lexical variable, as opposed to the usual global special.
: My compiler, Allegro CL, in its infinite wisdom decided I really wanted
: *cont* to be special, and so does it for me. Normally, this is convenient,
: but not now; the macros really depend on it being lexical.
: How do I do this? Portable would be nice, because I'd like the utilities to
: run on CMU CL as well.
CMUCL will also make it special if you don't set some flag. Most of the
time it's the "right" thing to do.
Groetjes, Peter
--
It's logic Jim, but not as we know it. http://hipe.uia.ac.be/~s950045
Look in keyservers for PGP key.
>CMUCL will also make it special if you don't set some flag. Most of the
>time it's the "right" thing to do.
Granted; this is the only time I have ever had to do this. Kent Pitman
supplied a macro that should work everywhere (thanks again!).