This is the mail archive of the
mailing list for the Kawa project.
Re: Strange Binding
- To: Emmanuel Castro <castro at lirmm dot fr>
- Subject: Re: Strange Binding
- From: Per Bothner <per at bothner dot com>
- Date: 13 Aug 2000 22:14:15 -0700
- Cc: kawa at sourceware dot cygnus dot com
- References: <39940AE1.1DD3F705@lirmm.fr>
Emmanuel Castro <email@example.com> writes:
> Consider the following program:
> (define plus +)
> (define glob 5)
> (define (p) (display plus) (display (plus glob glob)) (newline))
> (define (q) (set! glob 8) (set! plus -))
> It prints out:
> #<procedure +>10 // ok, 5 + 5 makes 10 , then changing plus to - and
> glob to 8
> #<procedure ->16 // here, plus is both -, and +. In fact it should print
> #<procedure ->0
> I suppose that it is due to compilation optimisation.
Yes, the compiler is deciding it can inline the call to plus, because
it thinks it has the value it has, which is the same as the + procedure.
By the way, this only happens when compiling a declaration-at-a-time,
which does not happen when compiling a file, only when loading or evaluating
it. I.e. whan p is compiled *after* plus has been defined.
It is not obvious how to fix the problem, except by disabling inlining.
I.e. how does the compiler inline:
(+ glob glob)
(plus glob glob)
in an environment where both + and glob are bound to the same value?
Still, we should figure this out, as I think we want + to be inlined,
but plus not to be inlined (unless the compiler can *prove* it own't
get re-assigned, such as if plus is a lexical variable o declared
Of course there should be a flag to disable/control inlining!
> Maybe changing the value of
> a variable whose the value was a primitive function should show a warning.
I don't think we want that problem, since I think doing just that is
quite a reasonable thing to do.