[plt-scheme] r6rs eval + phases + exceptions

From: Stephen Wrobleski (steve at localtoast.org)
Date: Tue May 20 23:00:44 EDT 2008

Hi,

I have a a bit of a problem with values getting passed between phases. I'm
calling r6rs:eval on an expression that may throw arbitrary exceptions in a
syntax expander. As such, a value from phase 1 (of the eval) has now escaped
into phase 0 of the running program. I would like to programmatically test
for these exceptions, but of course none of my phase 0 predicates work
because they're from a different instantiation. (Actually the r6rs condition
library predicates don't work either, so r6rs:simple-conditions ends up
mangling the exception)

I can still test for exn:fail. It seems that exn:fail must have the same
identity across phases, since it's part of the core implementation.

Reading the documentation about such things, I came across the following bit

doc/reference/syntax-model.html:
> When the expander encounters require and require-for-syntax within a
> module context, the resulting visits and instantiations are specific to
> the expansion of the enclosing module, and are kept separate from visits
> and instantiations triggered from a top-level context or from the
> expansion of a different module.

I don't see how the above can be anything but completely false. I notice
that the modules do get instantiated multiple times, but every use of the
module uses the same instantiation (as it has to be for values retrieved by
syntax-local-value to work). (Also, why _are_ modules instantiated so many
times when required for-syntax (looking at their side effects) ?)

The only workaround I've come up with is to pass the phase 1 exception back
into eval and have a syntax expander pick it out and somehow turn it into
the phase 0 representation of the same exception. This seems needlessly
complex, and not generalized for the case of an exception thrown from phase
2 or higher.

Is there a better solution? It seems there's a lot of flexibility in
mzscheme's underlying namespaces. Could r6rs:environment be changed to
eliminate this problem? Given that eval expands and then immediately
executes code (with no possibility for independent compilation steps), it
would make sense to me if any for-syntax includes just referenced
already-existing phase 0 instantiations.


Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.racket-lang.org/users/archive/attachments/20080520/347bbdcc/attachment.sig>

Posted on the users mailing list.