From: Graham Hughes
Subject: Global lexical variable?
Date: 
Message-ID: <6l07tq$8gu$1@oak.treepeople.dyn.ml.org>
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.

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 <·····@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

From: Kent M Pitman
Subject: Re: Global lexical variable?
Date: 
Message-ID: <sfwbtsb6b0c.fsf@world.std.com>
······@A3162.resnet.ucsb.edu (Graham Hughes) writes:

> 
> 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))
From: David Bakhash
Subject: Re: Global lexical variable?
Date: 
Message-ID: <cxjogwbp1yc.fsf@hawk.bu.edu>
what is the meaning of a global lexical variable.  I also remember
seeing mention of this in Graham's book, but he didn't get into it, as
far as I know.  Can someone tell me of an instance in which this would 
be useful?  I guess I can imagine but I often think of indefinate
extent and global as the same thing. 

dave
From: Kent M Pitman
Subject: Re: Global lexical variable?
Date: 
Message-ID: <sfwpvgrytil.fsf@world.std.com>
David Bakhash <·····@bu.edu> writes:

> 
> what is the meaning of a global lexical variable.  I also remember
> seeing mention of this in Graham's book, but he didn't get into it, as
> far as I know.  Can someone tell me of an instance in which this would 
> be useful?  I guess I can imagine but I often think of indefinate
> extent and global as the same thing. 
> 
> 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...
From: Peter.VanEynde
Subject: Re: Global lexical variable?
Date: 
Message-ID: <Eu87tx.GwF@uia.ua.ac.be>
Graham Hughes <······@A3162.resnet.ucsb.edu> wrote:
: 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.

: 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.
From: Graham Hughes
Subject: Re: Global lexical variable?
Date: 
Message-ID: <6lkdlr$c6e$1@oak.treepeople.dyn.ml.org>
"Peter.VanEynde" <·······@hhipe.uia.ac.be> writes:

>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!).
-- 
Graham Hughes <·····@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