[plt-scheme] redefining primitive syntax
Is there a way to redefine primitive syntax so that anything that
expands to it is also redefined? Suppose I want to convert
`let-values' forms to use `lambda' instead. How do I also get `let',
`let*', etc to be converted?
Welcome to MzScheme version 204.8, Copyright (c) 1995-2003 PLT
> (define-syntax let-values
(syntax-rules ()
((_ (((var) expr) ...) body ...)
((lambda (var ...) body ...) expr ...))))
> (syntax-object->datum (expand '(let-values (((x) 3)) x)))
(#%app (lambda (x) x) (#%datum . 3))
> (syntax-object->datum (expand '(let ((x 3)) x)))
(let-values (((x) (#%datum . 3))) x)
My guess as to what's happening is that the `let' syntax transformer
has a binding to the `let-values' in the mzscheme module, so it uses
that rather than the current top-level binding. Which makes me think
`fluid-let-syntax' is what I want, but I couldn't get that to work
either:
> (syntax-object->datum
(expand
'(fluid-let-syntax ((let-values
(syntax-rules ()
((_ (((var) expr) ...) body ...)
((lambda (var ...) body ...) expr ...)))))
(let ((x 3)) x))))
(let-values (((x) (#%datum . 3))) x)
Is there some easy way to do what I want? I would be happy with a
function from syntax objects to syntax objects that replaced all
occurences of `let-values' with the appropriate `lambda' expressions;
the only way I can think of to do this is to structurally recurse on
the result of `expand', using a big `syntax-case' for all the
primitive syntax forms, but this is a little tedious.
--dougo at ccs.neu.edu