From: Chun Tian (binghe)
Subject: Page 268 of <On Lisp>...
Date: 
Message-ID: <1139415382.696808.28150@g47g2000cwa.googlegroups.com>
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.

From: Thomas F. Burdick
Subject: Re: Page 268 of <On Lisp>...
Date: 
Message-ID: <xcvbqxh38m6.fsf@conquest.OCF.Berkeley.EDU>
"Chun Tian (binghe)" <··············@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!        |
   (   -.  |       `-----------------------'
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Chun Tian (binghe)
Subject: Re: Page 268 of <On Lisp>...
Date: 
Message-ID: <1139457485.662820.242700@g43g2000cwa.googlegroups.com>
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:)
From: Ivan Shvedunov
Subject: Re: Page 268 of <On Lisp>...
Date: 
Message-ID: <44uugnF42u42U1@individual.net>
Chun Tian (binghe) wrote:
> 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.
> 

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