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]

variable binding


Hello,

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

I guess Guile determines the binding of `+' when `foo' is first called,
not when it is defined.  Also, it seems Guile overwrites the binding
only at the first time `define' is called in a module:

  % guile -q
  guile> (define + +)
  guile> (define (foo) (+ 1 2))
  guile> (foo)
  3
  guile> (define + -)
  guile> (foo)
  -1

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.  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?

Thanks in advance.

Keisuke Nishida

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