This is the mail archive of the
guile@sources.redhat.com
mailing list for the Guile project.
Re: variable binding
- To: Keisuke Nishida <kxn30 at po dot cwru dot edu>
- Subject: Re: variable binding
- From: Mikael Djurfeldt <mdj at mdj dot nada dot kth dot se>
- Date: 24 Aug 2000 19:07:40 +0200
- Cc: guile at sourceware dot cygnus dot com
- Cc: djurfeldt at nada dot kth dot se
- References: <m3lmxn9rvi.fsf@indy.STUDENT.CWRU.Edu>
- Reply-To: djurfeldt at nada dot kth dot se
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!'.