[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Question with binding
I have been thinking about compiling scheme, and am confused about the
following possibility:
(define foo (lambda (x) (+ x 2)))
(define + (lambda (x y) something))
(foo)
If this is legal, I don't understand how a compiler can validly inline
primitives. Is there some provision in R3RS or R4RS that resolves
this problem, or is it really a problem? If the latter, how do
compilers deal with it?
Hopefully calling foo with no arguments gives a "wrong number of
arguments error" irrelevant of whether + is open coded. :-)
Now seriously, according to (my interpretation of) r3rs/r4rs,
assigning a new value to the variables which hold the standard
procedures is legal, and should have the "expected" effect. Thus open
coding standard procedures is "strictly" illegal in a pure r3rs/r4rs
environment.
In MIT Scheme, no open coding happens by default, and there are no
constant bindings. There are, however, a variety of declarations, of
which the most frequently found is
(declare (usual-integrations))
which tell the compiler that some set of common variables will have
their standard values at run time and that the compiler can freely
integrate/open-code these values.
In the absence of this (or another relevant) declaration, the compiler
will issue code which will act as if it referenced the variable at
call time and then invoked the resulting value. Thus changing the
value of + at run time will change the behavior of compiled code that
references +.