[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question with binding



In article <8904171910.AA26688@polya.Stanford.EDU> shap@POLYA.STANFORD.EDU (Jonathan S. Shapiro) writes:
>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?
>
>Jon

Indiana University's Schemefolk treated this problem as follows (it's
possible I err here, in which case I profusely apologize to those
concerned): 

A bunch of primitive functions, e.g., +, cons, etc., were treated as
_constants_ in the sense that the names could not have other values
assigned to them. This is not weird, since it recalls the usual
treatment of certain other constant names, e.g., 1, nil (or rather
#f), "hello", etc.  Thus your (define + ...) would bomb.

They went on to add the facility (declare-constant ...) to the
language (Scheme84) so that the user could define hir own set of
constants. This was merely for the user's convenience, _not_ a
directive to the compiler to inline.

Just to make things interesting, they also added the facility
(undeclare-constant ...). It works as expected for user-defined
constants, which aren't inlined anyway. But for the system-constants,
while previous inlining stays, any new uses of the constant name take
on the new definition if any. (Is that clear? >:-])

--dorai
------------------------------------------------------------------------------
We must believe in free will. We have no choice.       --Isaac Bashevis Singer
------------------------------------------------------------------------------