[plt-scheme] require-for-syntax issues

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Jul 9 21:23:11 EDT 2003

At Wed, 9 Jul 2003 20:24:09 -0400, "Felix Klock's PLT scheme proxy" wrote:
> Then, in the interactions buffer for "mod2", I can execute:
> Welcome to DrScheme, version 204.
> Language: (module ...).
>  > (opaque-3 'food (list 'apple 'banana 'pear))
> #(struct:opaque-object food (apple banana pear))

That's a bug. It should have been an error.

The bug is related to debugging annotations. (You'll get the correct
error if you turn off debugging in DrScheme through the language

More details, for the interested:

The underlying problem is in how the module+macro system supports the
interactive, top-level environment. This support means expanding just
enough, then evaluating just enough, then expanding a little more, etc.
Your example shows how `expand' and other functions are not quite right
for this task.

In particular, for debugging, DrScheme first expands each top-level
expression with `expand-to-top-form'. That much produces

 #'(make-opaque-object (quote food) (list (quote apple) (quote banana) pear))

but with no bindings in phase 0. So far so good.

But DrScheme then sends the expression to `expand'. The `expand'
function is designed to take a syntax object generated by
`read-syntax', which means a syntax object with no context. So `expand'
adds phase 0 and phase 1 bindings (from the top-level environments) to
its argument if it doesn't already have the bindings.

That's where things go wrong in this case. The syntax object passed to
`expand' isn't supposed to get phase 0 bindings from the top-level

Probably we need a variant of `expand', `eval', etc. that does not add
top-level bindings to its argument. Then we have to adjust DrScheme
(and other tools) to use the right variant of `expand'.


Posted on the users mailing list.