Michele Simionato <[email protected]> writes:

> On Mon, May 25, 2009 at 4:31 PM, Alex Shinn <[email protected]> wrote:
>>> Ok. Anybody here knowing Common Lisp can tell me how Common Lisp
>>> would work in that example?
>>
>> Well, you couldn't do (defvar foo lambda) to begin with
>> since lambda isn't a variable.  But nothing like this is
>> remotely possible in any language that does any sort of
>> analysis, since bar is compiled before it is ever called.
>
> No, I meant my own example translated to Lisp:
>
> (let ()
>   (defvar a 42)
>   (defmacro m () a)
>   (m))
>
> Both emacs-lisp and CLisp at the REPL behaves as Guile, i.e.
> they have no phase separation.

This isn't actually a correct translation.  DEFVAR and
DEFMACRO actually act at the top-level, even when wrapped
inside a LET.  If you try it yourself, both a and m are
still defined outside that LET.

A better translation would be

  (let ((a 42)) (macrolet ((m () a)) (m)))

which indeed will give you the error:

  ...
  Compile-time error:
    (in macroexpansion of (M))
  (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
  The variable A is unbound.
  ...

in CL (checked in SBCL).  In Emacs it still works.
Technically CL implementations are allowed, but not
required, to support this.  From the CLHS:

  The macro-expansion functions defined by macrolet are
  defined in the lexical environment in which the macrolet
  form appears. Declarations and macrolet and
  symbol-macrolet definitions affect the local macro
  definitions in a macrolet, but the consequences are
  undefined if the local macro definitions reference any
  local variable or function bindings that are visible in
  that lexical environment.

> You misunderstood, but this is natural because slides should be
> accompained by spoken works ;-) I wrote that phases are "new"
> (using quotes) and I would have explained in words that phases
> per se are not a new concept: what is "new" is that for the first
> time the Scheme committee has specified the evaluation strategy
> of Scheme programs in detail. AFAIK, in the past Guile behavior
> would have been consistent with the standard.

Which standard?  R5RS had no low-level macros, so you can't
apply this test.  However, R4RS had low-level hygienic
macros back in 1991, and in it DEFINE-SYNTAX was only
allowed at the top-level.

-- 
Alex

Reply via email to