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

redefining syntax at the top level

I find section 5.3 (Syntax Definitions) a bit confusing.  I think
the 8-line sentence beginning "Although macros may expand into
definitions and syntax definitions..." should be unpacked and explained
more clearly.  Rationales for each of the example errors should
be given.

Here are some things I'd like to be able to do at the top level:

;; redefine if to be a normal variable holding a procedure, specifically
;; the procedure lazy-if, defined earlier

(define if lazy-if)

;; redefine lambda to be equivalent to lazy-lambda, a macro defined
;; earlier in terms of the standard definition of lambda.

(define-syntax lambda
               (syntax-rules ()
                  ((lambda arg-clause body-expr ...)
                   (lazy-lambda arg-clause body-expr ...))))

I can't tell whether these things are supposed to be legal.  They seem
to me perfectly reasonable, and not difficult to support.  They also
seem quite important for transformational programming and metalevel
programming---which are my favorite applications of macros.

I'd expect these things to work, by analogy to the way you can
redefine a normal binding in terms of its own old value.  In the
case of syntax bindings, the relevant ordering would not be the
runtime evaluation ordering, but the compile-time definition and
use ordering.

In case you're interested in this problem...

As you've probably guessed, I'm writing a package to convert Scheme
into lazy Scheme simply by redefining most simple procedures to expect
and return promises.  (And redefining strict primitives to return a promise
to force their arguments and perform the actual primitive operation
on the actual values.)

If I can just redefine if and lambda, I can then just load in the usual
macros that define cond, define, etc., then load in normal procedure
definitions of append, map, etc. to rebuild most of Scheme as a lazy

I'd like to do this portably, and I'd really rather not have to use a
let-syntax and put the whole lazy Scheme program in its body.  I want
people to be able to just load a file, and _voila_---they're in lazy
Scheme, without having to write a new interpreter or compiler.  Writing
a new read-eval-print loop wouldn't be too bad, but there doesn't seem
to be any way to reify the right environment and pass it to eval.
(We can do equivalent things in RScheme using modules, but I'd like
a portable version.)

Similar problems arise when trying to implement an optimized metaobject
protocol portably.