[plt-scheme] On hygiene and trust

From: Abdulaziz Ghuloum (aghuloum at gmail.com)
Date: Wed Jul 8 20:41:01 EDT 2009

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.)])))


>>> defmacro is really easy to use and understand, but isn't hygienic.
>>
>> I don't agree that defmacro is easy to use without a pattern
>> matching facility.  Again, write the example that you provide
>> (above) using defmacro; I doubt it will be simpler or easier
>> or more robust, or anything.
>
> Do you consider backquote a pattern matching facility?

Not really.

> ;; Common lisp version of named-let
> (defmacro named-let (name bindings &body body)
>   `(LABELS ((,name ,(map 'list #'car bindings) , at body))
>      (,name ,@(map 'list #'cadr bindings))))

This code has a bug that's not related to hygiene but to the scope
of the "name" identifier.  But either way, I don't see that as simpler
or easier to use than, say, the following (exhibiting the same bug):

(define-syntax-rule
   (named-let name ((lhs* rhs*) ...) b b* ...)
   (letrec ((name (lambda (lhs* ...) b b* ...)))
     (name rhs* ...)))

It looks like named-let is a trivial macro that can be handled
trivially in any macro system, so, it does not really show that
"defmacro is really easy to use and understand".  As the complexity
of the macro increases, doesn't it just cause more littering with
all of these map this and map that and splice this and that?

Aziz,,,

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 mean, you know macros,
and none of this is new to you, but do you really find manipulating
S-expressions that much easier and simpler than manipulating syntax
objects?  Or is it something else?



Posted on the users mailing list.