[plt-scheme] Unit/sig and hygiene

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Mon Oct 16 04:39:18 EDT 2006

Matthew Flatt skrev:
> [Sorry for the delay...]
> 
> At Thu, 28 Sep 2006 10:54:36 +0100, Dave Gurnell wrote:
>> We have a problem with the interaction between signed units and  
>> hygiene.
> 
> I don't think your problem has anything to do with units. It has to do
> with `syntax-local-introduce' and modules:
> 
>>    (define-syntax (define-snooze-interface stx)
>>      (syntax-case stx ()
>>        [(define-snooze-interface db@)
>>          (syntax-local-introduce
>>           #'(begin
>>           [...]
> 
> Here's a simpler program with the same problem:
> 
>   (module ma mzscheme
>     (define-syntax (def-a stx)
>       (syntax-case stx ()
>         [(_)
>          (syntax-local-introduce
>           #'(begin
>               (define a 5)
> 
>               (define-syntax get-a
>                 (syntax-rules ()
>                   [(_) a]))
> 
>               (provide get-a)))]))
>     (provide def-a))
> 
>   (module mb mzscheme
>     (require ma)
>     (def-a)
>     (printf "~a\n" (get-a)))
> 
> I think the problem is best characterized as a bug in MzScheme's
> handling of module-top-level bindings. MzScheme's expander doesn't
> introduce a suitable of renaming for `a', because the defined `a'
> appears not to come from a macro (since the macro uses
> `syntax-local-introduce' to hide the introduction).
> 
> I'll look into fixing it, but I'll have to think more about whether
> syntax-local-introduce' can cause other, similar problems. Meanwhile, I
> recommend trying to use `datum->syntax-object' instead of
> `syntax-local-introduce'.

In the above example, it seems syntax-local-get-shadower saves
the day.

(module ma mzscheme
     (define-syntax (def-a stx)
       (syntax-case stx ()
         [(_)
          (syntax-local-introduce
            #`(begin
                (define a 5)

                (define-syntax get-a
                  (syntax-rules ()
                    [(_) #,(syntax-local-get-shadower #'a)]))

                (provide get-a)))]))
   (provide def-a))

(module mb mzscheme
   (require ma)
   (def-a)
   (printf "~a\n" (get-a)))


Dave, see also:

<http://www.scheme.dk/blog/2006/05/how-to-write-unhygienic-macro.html>


-- 
Jens Axel Søgaard



Posted on the users mailing list.