This does strike me as a serious problem (and it's a spanner in the works for implementing R6RS libraries). In effect, isn't the bug saying that Guile's syncase macros aren't totally hygienic? That is, in my example, if you provide your own binding for `foo-function' in the REPL environment, then that will be used in the evaluation of the transformed expression instead of the one in `(foo-module)', which is certainly *not* the intent of the macro author.
However, as a novice who's spent some time poking around in ice-9/boot-9.scm and `(ice-9 syncase)', I'm sort of confused about why this is hard -- isn't this metadata available? The transformer should have access to the closure in which it was created, and at creation time, we certainly know which identifiers are free and which ones aren't -- and we can look up the variables bound to the free ones in the transformer's lexical closure. The real issue with modules is that they hide bindings, not variables. If you have the variable, you can use it, no matter which module is current. On Thu, Mar 19, 2009 at 12:32 PM, Andreas Rottmann <a.rottm...@gmx.at> wrote: > Julian Graham <jool...@gmail.com> writes: > >> Hi Guilers, >> >> Alright, I've been banging my head against this for several weeks now >> and only just had the time to sit down and research this: If you use a >> symbol in an `(ice-9 syncase)' macro definition that's bound in the >> lexical closure in which that definition lives, then that binding >> should be the one that gets used at transformation time. At least, >> that's how I interpret the following bit of R5RS: >> >> "If a macro transformer inserts a free reference to an identifier, the >> reference refers to the binding that was visible where the transformer >> was specified, regardless of any local bindings that may surround the >> use of the macro." >> >> ...but that's not what Guile seems to do. (I'm fiddling around in >> 1.9.0 HEAD, because the VM is awesome and because there are some >> already-committed syncase fixes that have been useful to me...) If >> you create the following module: >> >> (define (foo-module) >> #:use-module (ice-9 syncase) >> #:export-syntax (foo-macro)) >> >> (define (foo-function) (display "Hello, world!")) >> >> (define-syntax foo-macro >> (lambda (stx) >> (syntax-case stx () >> ((_) (syntax (foo-function)))))) >> >> ...and then import `(foo-module)' into the REPL or somewhere else, >> evaluating `(foo-macro)' throws an error because `foo-function' can't >> be found. What am I doing wrong? >> > Nothing, this is a deficiency in Guile: > https://savannah.gnu.org/bugs/?20941. I wonder why it is marked as > "invalid", though. > > Regards, Rotty >