On Sep 14, Jed Davis wrote:
> On Fri, Sep 11, 2009 at 01:10:01AM -0400, Eli Barzilay wrote:
> >
> > But if you consider macros with a module system: it allows you to
> > keep the abstraction barrier by letting you export a macro but not
> > utility functions and values that the macro uses, and it allows
> > you to define your own language (for example, a language with a
> > new kind of `if') and still be able to import macros that are
> > written in the usual Scheme language.
> 
> Both of these use cases work just fine with Common Lisp's defmacro,
> because CL symbols are interned with respect to a package.  A macro (or
> anything else) whose definition contains a given symbol will continue to
> refer to that same symbol, regardless of what might happen to different
> symbols that happen to share its name.

Yes, they "work" for some *very* weak definition of "work".
Specifically about the two cases:

1. In this case CL just throws its hands in the air and provides
   absolutely no abstraction barriers.  Any function in any package is
   *always* available to *any* code.  (And yes, I know how CL
   advocates defend this, and I know the "thieves" quote.  It's still
   broken.)  A very simple example in PLT:

     #lang scheme
     (provide foo)
     (define-syntax-rule (foo) (bar))
     (define (bar) 1)

   Actually, PLT takes this another step further and if you try to:

     > (require "the-above-file.ss")
     > (eval (cadr (syntax->list (expand '(foo)))))
     the-above-file.ss:3:32: compile: access from an uncertified
     context to unexported variable from module:
     "/tmp/the-above-file.ss" in: bar

2. As for defining new languages based on given ones, like a new
   definition of `if' -- this is also "possible" with CL, but you're
   left with doing the name management yourself.  In this case it
   would roughly be declaring that you're shadowing `if', then
   referring to the CL version with a ::-qualified name when you need
   it.  Your new language is similarly suffering from all the usual CL
   constructs being available, so people can still break your
   carefully-laid abstractions.  Again, a quick PLT example:

     #lang scheme
     ;; provides a language like `scheme' except for `if'
     (provide (except-out (all-from-out scheme) if)
              (rename-out [if* if]))
     (define-syntax-rule (if* cond then else)
       (if (equal? cond 0) then else))


> One might almost be tempted to declare that defmacro is "perfect",

Yes.  Almost.

IMO, the conceptual jump from `defmacro' to hygienic macros is similar
in magnitude to the jump from CPP to `defmacro'.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to