[plt-scheme] On hygiene and trust

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jul 9 13:47:17 EDT 2009

On Jul  9, Joe Marshall wrote:
> On Wed, Jul 8, 2009 at 5:41 PM, Abdulaziz Ghuloum<aghuloum at gmail.com> wrote:
> >
> > On Jul 8, 2009, at 6:04 PM, Joe Marshall wrote:
> >
> >> On Wed, Jul 8, 2009 at 7:31 AM, Abdulaziz Ghuloum<aghuloum at gmail.com>
> >> wrote:
> >>>
> >>> I don't agree.  Show me a painful simple use.  Pick any simple
> >>> macro you want: let, let*, or, and, cond, case, or any other
> >>> macro of your choice to show the pain.
> >>
> >> This came up the other day.  Transform something like this:
> >>
> >> (define-event foo bar (arg1 arg2 ...)
> >>   (form1)
> >>   (form2 ...) etc.)
> >>
> >> into something like this:
> >>
> >> (define (foo$bar arg1 arg2 ...)
> >>   (form1)
> >>   (form2 ...) etc.)
> >
> > I don't see the pain caused by "syntax-case", and maybe I don't
> > understand the problem you're having.  Can you please write your
> > macro in syntax-case because my attempt below probably does not
> > do what you had in mind.
> >
> > (define-syntax define-event
> >  (lambda (stx)
> >    (define (concat x y) --- fill in the blank ---)
> >    (syntax-case stx ()
> >      [(_ foo bar (arg1 arg2 ...)
> >          (form1)
> >          (form2 ...) etc.)
> >       #`(define (#,(concat #'foo #'bar) arg1 arg2 ...)
> >           (form1)
> >           (form2 ...) etc.)])))
> 
> (define-syntax define-event
>  (lambda (stx)
>    (define (concat . x)
>     (string->symbol (apply string-append (map symbol->string x))))
>    (syntax-case stx ()
>      [(_ foo bar arguments form1 . body)
>       #`(define (#,(concat #'foo '$ #'bar) . arguments)
>           form1 . body)])))
> 
> (define-event foo bar (x y) (list x y))
> collects\scheme\private\map.ss:22:17: symbol->string: expects argument
> of type <symbol>; given #<syntax:3:16>
> 
> This is what usually happens when I try to use syntax-case.

How is that different than any other type error, say (concat 1 2)?

The bottom line is that a hygienic system needs to store more
information, so you need to put it somewhere.


> > PS. I'm just trying to understand your position, since I was
> > pretty surprised that *you* find defmacro style superior to
> > anything else in scheme (modulo hygiene as you said).
> 
> I didn't say that.  I said it was easier to understand what the
> defmacro form is doing to the code.  The transformation from
> list-structure to different list-structure is pretty
> straightforward.  Syntax objects are more opaque: #<syntax:3:16>
> 
> What is that?  [...]

A deficiency of the standard printer.


> I can't `mapcar' over a syntax object.

Sure you can, use `syntax->list' with `map'.


> And when I go in the other direction, I have the symbol `foo' and I
> wish to create some code that uses it, I have to transform it into a
> syntax object with the appropriate scope.

(Same as above -- you need to add the extra information.)


> On the other hand, I don't much like syntax-case.  It is much more
> complicated to use, and I see it used too often.
> 
> I want something else.  I'm not sure what, though.

This is the same thing that drives me crazy over and over.  There's
hardly any magic in `syntax-case' -- and in fact, you could just as
well write macros in a `syntax-case'-based systems without ever using
it.  For example:
  http://blog.plt-scheme.org/2009/05/explicit-renaming-macros-implicitly.html

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


Posted on the users mailing list.