[plt-scheme] define-values/invoke-unit in an internal definition context
At Sat, 11 Oct 2008 13:03:27 -0400, Abdulaziz Ghuloum wrote:
> Side Note: Ikarus has an internal module form that was borrowed
> from Chez and is described in Oscar Waddel's dissertation. My
> implementation had a similar problem.
>
> This example, similar to the one on top using sigs has a macro
> that expands to an import and a reference. It didn't work at
> first but now it now correctly and produces a=12.
>
> (let ()
> (module M (a)
> (define a 12))
> (define-syntax f
> (syntax-rules ()
> [(_)
> (let ()
> (import M)
> (printf "a=~s\n" a))]))
> (f))
>
> The counter example is the following where you have a macro
> that expands to an import wrapping an expression that contains
> module identifiers. This doesn't work now (and it shouldn't
> because import should be hygienic) but it used to work in the
> broken implementation of Ikarus. This is essentially how the
> use-unit@ macros works (above) and how it will break once the
> signatures are fixed.
>
> (let ()
> (module M (a)
> (define a 12))
> (define-syntax f
> (syntax-rules ()
> [(_ id)
> (let ()
> (import M)
> (printf "a=~s\n" id))]))
> (f a))
Thanks very much for your note!
I must say that I was confused about this message for a while. I
thought you meant that you incorrectly implemented the algorithm that
Oscar defined. But from my earlier study of Oscar's system, I expected
the examples above to behave in exactly the way that you claim is
broken. The again, `petite' (v7.3) as well as `ikarus' (current from
bzr) gave your predicted result.
It eventually dawned on me that someone fixed Oscar's algorithm itself,
perhaps since v6.9 of `petite' that I was using originally. You didn't
say how the algorithm was fixed, but after a few more experiments, it
was easy enough to guess: the expander takes a diff of the lexical
context on the use of a module id compared to the binding of the
module, and it applies that diff to the module's exported ids when
they're unpacked by `import'. Sure enough, when I look at
"psyntax.expander.ss", I see the diff-transferring operation in
`module-interface-exp-id*'. And in "psyntax.ss" from Kent's page, I see
that `lookup-import-binding-name' acquired a new `new-marks' argument
between versions 6.9 and 7.0.
Is that all correct?
You're completely right that the treatment of bindings with units was
based on Oscar's (old) `module', and that's why we have the (old) bug.
I will look into adding a context-diff-and-apply operation to PLT
Scheme's macro system.
Thanks,
Matthew