Comment 4 for bug 225387

Revision history for this message
Stephen Wrobleski (mindslight) wrote :

It looks like my email reply to <email address hidden> didn't make it here even though I didn't get an error.

Explicit expansion is the obvious case of something you can't do under r6rs
(+ikarus) that would be enabled

; "expands" the outer level of the given expression
; 1. assumes the first element is a syntactical keyword
; 2. does not deal with expansions of the other elements, nested forms, or a
; new returned syntax form

(define (expand-outer stx)
  (syntax-case stx ()
    [(id etc ...)
     ((syntax-local-value #'id) stx)]))

Fixing the restrictions in the example would create a full-functional explicit
expansion mechanism. Such explicit subexpansion would be necessary to
implement functionality similar to the local defines of let and lambda.

(define-syntax define-five
  (syntax-rules (define-five)
    [(define-five id)
     (define id 5)]))

; evaluates to 5
(let ()
  (define-five vv)
  vv)

a user-defined 'let' can only know what to do with define-five after it
explicitly expands and sees that it's a define clause (rather than an
expression)

Imagine a 'class' syntax definition, which uses two keywords 'method' and
'field'. The keywords are defined to raise an error, and the 'class' expander
does a free-identifier=? to test for their usage.

To be able to create a new definition on top of that library (without touching the
library itself), the class macro must explicitly pre-expand forms so that it
can check for returned method and field forms.

There are cases where I would like to be able to check for the presence of a
syntactical definition rather than blindly expanding, which is why I see
syntax-local-value as more useful than a generic expand.

..

For the case of arbitrary values being passed around at expansion time as
syntactical keywords, think of the r6rs syntactic record layer. When
defining a record, a syntactical definition is created for the 'type', which
is used by further macros to influence the code they generate. I'd like that
generalized capability to use in my own code.

...

When not transforming, syntax-local-value errors out (as there is no
transformer environment to look in)

When called on kernel syntax (like #'if), syntax-local-value also errors
out, as it is not a syntax transformer.