This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: variable binding


Keisuke Nishida <kxn30@po.cwru.edu> writes:

> I'm not sure if this is a bug or a feature, but Guile does the following:
> 
>   % guile -q
>   guile> (define (foo) (+ 1 2))
>   guile> (foo)
>   3
>   guile> (define + -)
>   guile> (foo)
>   3
> 
> But,
> 
>   % guile -q
>   guile> (define (foo) (+ 1 2))
>   guile> (define + -)
>   guile> (foo)
>   -1

It's a bug in original design of the current module system.

> I guess this is because `define' creates a new binding in a module when
> first called, then it works same as `set!' as written in R5RS.

Yes.

> However, when a variable is imported from another module, a new
> binding is not created, and Guile uses the location created in the
> other module.
> 
> My question is what is the expected behavior.  How should `define' work
> with modules, and when should bindings be resolved?

This is not defined by R5RS.  I think the safest and most useful
behaviour is if `define' always "begins" with creating a new binding
in the local module, and then behaves as specified in R5RS, i.e., as
`set!'.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]