Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Page 268 of <On Lisp>...

32 views
Skip to first unread message

Chun Tian (binghe)

unread,
Feb 8, 2006, 11:16:22 AM2/8/06
to
Hi, I'm a one-year lisp learner, and I'm reading Paul Graham's <On
Lisp>.
On page 268 (in chapter 20: Continuations), I just read this:

"... This distinction is important because these macros wouldn't work
if *cont* were not a local variable. That's why *cont* is given its
initial value in a setq instead of a defvar: the latter would also
proclaim it to be special."

And on page 267, I saw these code:

(setq *cont* #'identity)

(defmacro =lambda (parms &body body)
`#'(lambda (*cont* ,@parms) ,@body))
...
...

I just don't understood this: what's the difference between

(defvar *cont* #'identity)

and

(defvar *cont*)
(setq *cont* #'identity)

?? Help, thanks.

Ivan Shvedunov

unread,
Feb 8, 2006, 2:18:50 PM2/8/06
to

Take a look here: http://www.cliki.net/On%20Lisp

-- cut --

When defining continuation-passing macros (p. 267) Paul Graham seems to
be assuming that *cont* global variable has lexical scope. This
contradicts Common Lisp standard. With present day Common Lisp
implementations, the aforementioned macros just don't work. Also, this
issue can be very confusing for newcomers. Suggested solutions for
fixing the macros are (note that #'values is used instead of #'identity
- according to Paul Graham's Errata):

* emulate lexically scoped global variable *cont* using
symbol-macro that can be shadowed by let or lambda:
(defvar *actual-cont* #'values)
(define-symbol-macro *cont* *actual-cont*)
* just omit (setq *cont* #'identity) and call "top-level"
continuation-passing function as (=somefunc #'values ...)
* ...

-- cut --

Thomas F. Burdick

unread,
Feb 8, 2006, 3:20:49 PM2/8/06
to
"Chun Tian (binghe)" <tianchu...@gmail.com> writes:

> Hi, I'm a one-year lisp learner, and I'm reading Paul Graham's <On
> Lisp>.
> On page 268 (in chapter 20: Continuations), I just read this:
>
> "... This distinction is important because these macros wouldn't work
> if *cont* were not a local variable. That's why *cont* is given its
> initial value in a setq instead of a defvar: the latter would also
> proclaim it to be special."

DEFVAR proclaims its variable to be special. SETQ of a nonexistent
variable is undefined. What Paul Graham meant it to do was estabilish
a global binding without proclaiming the variable special. On Lisp
was written before the ANSI standard; the (now) standard way to do
what Graham was attempting here:

> And on page 267, I saw these code:
>
> (setq *cont* #'identity)

is instead:

(define-symbol-macro *cont* #'identity)

Note that it's also considered bad style to surround the name of a
non-special variable with *'s. *CONT* should have been named
something like =CONT=, or just CONT.

> I just don't understood this: what's the difference between
>
> (defvar *cont* #'identity)
>
> and
>
> (defvar *cont*)
> (setq *cont* #'identity)

Nothing at all. You might want to consider the difference between:

(defmacro defglobal (name val)
(let ((special (gensym)))
`(progn
(define-symbol-macro ,name ,special)
(defvar ,name ,val))))

(defglobal *cont* #'identity)

and:

(defvar *cont* #'identity)

(a hint, you can close over the first one)

--
/|_ .-----------------------.
,' .\ / | Free Mumia Abu-Jamal! |
,--' _,' | Abolish the racist |
/ / | death penalty! |
( -. | `-----------------------'
| ) |
(`-. '--.)
`. )----'

Chun Tian (binghe)

unread,
Feb 8, 2006, 10:58:05 PM2/8/06
to
Oh...

I think I need time to understand this, since I didn't understand the
note about the special declare in HypecSpec, a little stupid of me:)

0 new messages