Re: [Scheme-reports] ANN: first draft of R7RS small language available Eli Barzilay (29 Apr 2011 20:16 UTC)

Re: [Scheme-reports] ANN: first draft of R7RS small language available Eli Barzilay 29 Apr 2011 20:15 UTC

An hour ago, Andre van Tonder wrote:
> On Fri, 29 Apr 2011, Andre van Tonder wrote:
> >
> > Also, they cannot just use the original ER system, becasue it is
> > not compatible with modules or with syntax-case.  They would have
> > to adopt a modified version of ER such as the one provided in R6RS
> > Larceny.  This adaptation has a couple of additional primitives.
> > They are
> >
> >     bound-identifier=? (procedure) - to compare bindings that are
> >                                      syntax objects, where
> >                                      original ER would use eqv?
> >     datum->syntax      (procedure) - for hygiene breaking where
> >                                      original ER would have
> >                                      inserted raw symbols into the
> >                                      output, incompatible with
> >                                      modules and with syntax-case
>
> So you see that once you have accomodated modules and hygiene
> breaking correctly as in Larceny, you basically end up with an
> explicit renaming system that is SYNTAX-CASE without the pattern
> matching

(I have always considered the `syntax-case' form itself as nothing
more than something that is used for convenience.)

> (the compare procedure argument to the ER transformer is identical
> to FREE-IDENTIFIER=?, and you have to provide BOUND-IDENTIFIER=? and
> DATUM->SYNTAX anyway as above).
>
> So all that is missing is the pattern-template matcher and you have
> syntax-case.
>
> And since you already have gone to the trouble of implementing the
> pattern-template matcher-inserter in WG1 (for SYNTAX-RULES), the
> question becomes why /wouldn't/ you use it in WG2 and get
> syntax-case?

That's a *very* good question.

More than the technical issue, what makes me dislike ER is the E part.
You have to explicitly make your macro hygienic, so the common case of
a robust macro becomes much more verbose, which IMO is directly
encouraging not doing so (with the usual excuses that programmers give
themselves when they don't check the result of malloc()).

Disclaimer: I don't have an actual experience with ER macros, and most
of what I know about it comes from reading random stuff on the web.
A typical example that I've seen would be something like:

  (define-syntax swap!
    (lambda (form rename compare)
      `(,(rename 'let) ((,(rename 'tmp) ,(cadr form)))
          (,(rename 'set!) ,(cadr form) ,(caddr form))
          (,(rename 'set!) ,(caddr form) ,(rename 'tmp)))))

or a "tidier" form of the same:

  (define-syntax swap!
    (lambda (form rename compare)
      (let ((x (cadr form))
            (y (caddr form))
            (%tmp (rename 'tmp))
            (%let (rename 'let))
            (%set! (rename 'set!)))
        `(,%let ((,%tmp ,x))
           (,%set! ,x ,y)
           (,%set! ,y ,%tmp)))))

As I said in the previously quoted reply, I can't help looking at
these and feel sorry for the people who write such macros.
`syntax-case' is so great exactly because it preserves the convenience
of `syntax-rules' while allowing arbitrary code execution, and it's
also easy to have "everything hygienic by default".

I'm sure that something similarly convenient can be made for the
above horrors...  But that would pretty much be `syntax-case'.  In
fact, there seem to be something very similar that is mentioned at the
bottom of http://wiki.call-cc.org/explicit-renaming-macros , which
makes it possible to write:

  (define-syntax swap!
    (explicit-renaming (%tmp %let %set!)
      ((_ x y)
       (lambda (compare?)
         `(,%let ((,%tmp ,x))
             (,%set! ,x ,y)
             (,%set! ,y ,%tmp))))))

I see that, and the first thing that I can think about is -- if in
these things most of the macro result code a quasi-quoted form with
all identifiers unquoted, then why isn't that made easier?  The second
thing that I worry about is -- it seems awfully fragile and verbose
that I need to explicitly list all the identifiers that need to be
hygienic, since that's the common (and robust) case, why not specify
things the other way -- by listing non-hygienic identintifiers
instead.  (And implementing a solution for these things look like they
give me something that is close enough to `syntax-case' that any
difference is negligible.)

(But what do I know.  I'm also ignorant enough to not get the
self-whipping thing that some religions encourage.)

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

_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports