[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: macros expanding into definitions
> Can anyone suggest a workaround for this? I would like to be able to
> use macros like this in contexts that allow internal defines.
Yes. We should change the report to convert begin into a "splicing"
construct when it appears at top level or within the body of a lambda
or similar form. That is, (begin form ...) should be valid iff
form ... is valid in those contexts, and it should have the same
meaning. That is what the current syntax-case implementation does,
although due to a bogus optimization, the distributed version messes it
up in the case where the begin is the only expression in a lambda
body. With this rule, your first definition of define-multiple works
both at top level and internally:
> (define-syntax define-multiple
(syntax-rules ()
((define-multiple (name ...) exp)
(begin (define name #f) ...
(call-with-values (lambda () exp)
(lambda vals
(begin (set! name (car vals))
(set! vals (cdr vals)))
...))))))
> (define-multiple (a b c) (values 1 2 3))
> (list c b a)
(3 2 1)
> (let () (define-multiple (d e f) (values 1 2 3)) (list f e d)))
(3 2 1)
I know this wasn't quite the kind of workaround you were looking for,
but I think it's the right way to solve the problem.
Kent