guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wrapping `define-syntax'


From: Andy Wingo
Subject: Re: wrapping `define-syntax'
Date: Wed, 15 Apr 2009 13:25:26 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux)

On Mon 13 Apr 2009 00:55, Julian Graham <address@hidden> writes:

>   (define canonical-define-syntax (@ (ice-9 syncase) define-syntax))

This won't work as expected. Syncase macros cannot be bound with
`define'. From the R6RS:

    5.2. Variables, keywords, and regions

    Within the body of a library or top-level program, an iden-
    tifier may name a kind of syntax, or it may name a location
                                      ^^
    where a value can be stored.

    11.2.1. Variable definitions
                                                             
    The define form described in this section is a definition
    used to create variable bindings and may appear anywhere
                   ^^^^^^^^
    other definitions may appear.

    11.2.2. Syntax definitions

    The define-syntax form described in this section is a
    definition used to create keyword bindings and may ap-
                              ^^^^^^^
    pear anywhere other definitions may appear.

This probably should work in theory, but might not:

    (define-syntax canonical-define-syntax
      (@ (ice-9 syncase) define-syntax))

But... given that for your use case (I think), you are within a
`library' form, why not use with-syntax or let-syntax or what-have-you?

>   (canonical-define-syntax foo (syntax-rules () ((_) 'foo)))
>
> ...I get:
>
>   ERROR: In procedure vm-run:
>   ERROR: VM: Stack overflow

Hm, dunno.

>   (define canonical-define-syntax
>     (procedure->memoizing-macro (macro-transformer (@ (ice-9 syncase)
> define-syntax))))

This won't work either. In the syncase model, there is an extra
conceptual bit attached to a binding that indicates whether it is a
"keyword" binding or a "variable" binding. In Guile, we map this to an
object-property on variable objects. `define' will not set this bit.

Furthermore, the expander needs to be able to map bindings to expander
procedures. This could be done by looking at the variable's binding --
e.g. using variable-ref -- but syncase doesn't do it that way, it stores
the transformer itself in the *sc-expander* property on the variable
object.

Historically, this almost worked in our favor -- all syncase macros are
bound to sc-macro, an mmacro that allowed for integration with Guile's
first-class macros. (@ (ice-9 syncase) define-syntax) merely retrieves
#<macro! sc-macro>, not the /real/ information -- the *sc-expander*
property of the variable object.

These implementation details are just for your information; please don't
rely on any of it :-)

> So I'm curious: regardless of whether what I'm trying to do is a good
> idea, is it feasible -- and if so, what's the right way to do it?

Rebinding define-syntax lexically should be possible with let-syntax or
something like that, but I think there might be bugs with (define-syntax
foo bar).

Cheers,

Andy
-- 
http://wingolog.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]