This is the mail archive of the mailing list for the Kawa project.

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

Re: Strange Binding

Emmanuel Castro <> 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 -))
> (p)
> (q)
> (p)
> 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)
but not:
        (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.
	--Per Bothner

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