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

Question with binding



   Date: Tue, 18 Apr 89 01:07 EDT
   From: Andre van Meulebrouck <vanMeule@ALLEGHENY.SCRC.Symbolics.COM>

       Date: 17 Apr 89 20:36:41 GMT
       From: titan!dorai@rice.edu  (Dorai Sitaram)
       Subject: Re: Question with binding
       Message-Id: <3107@kalliope.rice.edu>

       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

       [...]
       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.  [...]

   ^^That's my understanding too:  the idea that certain procedures can't change
   during the course of a compilation/computation, otherwise things couldn't be
   guaranteed to make sense if they were meanwhile allowed to change underneath
   your feet during the computation/compilation.  As to user defined
   functions--well if you want to do those sorts of things with your own functions,
   okay, but the system won't let you do that with its functions (upon which it
   might depend, or otherwise feels some responsibility to protect the integrity
   of).  Something like that...(and I too profusely apologize if I misstated or
   oversimply stated...).

   In MacScheme, if you try (define + ...) you get:

   ERROR:  Integrable procedures may not be redefined.  
   (set! + ...)

   I like the idea of that a great deal...I don't think the convenience of being
   able to redefine things (advertently or inadvertently--with or without warning)
   is a wonderful feature.  You can always write your own similar functions with
   different names, and call out to those in preference if a system function isn't
   quite what you wanted, right?

       --dorai

Yes, but this may not be the correct way to think about things.  Lets say that
I want to count the number of cons cells that are formed in a suite of
programs.  A good way to do this might be to create an environment in which the
constructors like CONS and LIST were aliased to versions that counted the
number of cells they allocated.  The program suite could then be run in this
new environment to gather the desired statistics.  I would find the alternative
of modifying all of the programs in the test suite much less elegant and quite
inconvenient.  In on approach the cost of implementation is constant and in the
other it is proportional to the size of the test suite.
					Morry Katz
					katz@polya.stanford.edu