[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Are generated toplevel definitions secret?

On Sun 24 Apr 2011 17:42, Peter Bex <Peter.Bex@x> writes:

> On Sun, Apr 24, 2011 at 05:21:30PM +0200, Peter Bex wrote:
>> > 
>> >       (begin
>> >         (define-syntax define-getter
>> >           (syntax-rules ()
>> >             ((_ var init)
>> >              (begin
>> >                (define val init)
>> >                (define-syntax var
>> >                  (syntax-rules ()
>> >                    ((_) val)))))))
>> > 
>> >         (define-getter x 10)
>> >         (define-getter y 20))
>> > 
>> > If I put that in a chicken module, import the module, then evaluate (x)
>> > and (y), does that evaluate to 10 and 20, respectively?
>> Yeah.  Each macro carries its syntactic information with it, like a
>> closure.  So "val" in the macro expansion would refer to the x that is
>> defined in that module.
> I overlooked the fact that val is used, not var.  This will give an
> error because the "val" is defined in a different phase than the "var"
> macro is declared. 

Sorry, I should have been clearer with the names.  Your other remarks
refer to correct module scoping for free identifiers in macro output,
which is of course important.  (Before 2.0, Guile did this incorrectly.)

> If I change (define val init) to (define-for-syntax val init), the
> generated "var" macro will pick up on it.

I am suprised that you needed to do define-for-syntax here, as the
*value* of the `val' bindings is not needed at expansion time; the
expander must only note that there is such a binding.

> Then it will use the same "val" for both x and y, and hence it will
> overwrite the binding.  So it's basically the same as putting this in
> your module:
> (define val 10)
> (define val 20)
> I'm not 100% sure but I suppose this could be considered a bug.

This is what Andre was originally referring to, these "generated
toplevel definitions".  This would be the correct expansion if "val"
were bound in module A, and AIUI that has been chicken's argument, that
it treats all identifiers as bound, and therefore this expansion is

I believe that the R6RS argument is that one can determine which
identifiers are bound and which are not, and therefore an introduced
toplevel binding should not be visible to other code: it should be
"secret".  Indeed it makes sense as far as user expectations go, I
think.  However I don't know how to implement it correctly, and would
appreciate pointers if anyone has any.



Scheme-reports mailing list