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

Re: constant folding/smashing



    Date: 10 Jun 1988 11:03-EDT
    From: NGALL@G.BBN.COM

    ....
    And this brings up the second example of the confusion in constant
    folding that no one has yet addressed: Why are lists and strings
    (among others) constant folded, but not general vectors, since all of
    them are composite objects?  

What makes you think that is true?  (I assume you mean "coalesced", that
is, two distinct pieces of source text resulting in a single object in the
compiled program, rather than "constant folded", which means a pure function
with constant arguments replaced by its constant result.)  I don't of
anything that says that Common Lisp must treat quoted general vectors
differently from quoted strings.  If some implementations do so, that's
merely an implementation. 

    [3] (EQ (QUOTE #1=(1 2 3))  (QUOTE #1#)) => T or NIL, wow!!!!!

I see no evidence that any interpreter or compiler is permitted to
return NIL for the above form.  What you're probably thinking of
is (EQ (QUOTE #(1 2 3)) (QUOTE #(1 2 3))), which might be true or false.

Once you (or anyone else in this somewhat rambling and inconclusive
discussion) think you understand the issues above, figure out what
you think about these three forms:

  (EQ (FUNCTION (LAMBDA () 1)) (FUNCTION (LAMBDA () 1)))

  (EQ (FUNCTION (LAMBDA (N) (DO ((I 1 (1+ I)) (A 0 (+ A I)))
				((>= I N) A))))
      (FUNCTION (LAMBDA (N) (DO ((I 0 (1+ I)) (A 0 (+ A I)))
				((>= I N) A)))))

  (EQ (FUNCTION (LAMBDA (N) (DO ((I 1 (1+ I)) (A 0 (+ A I)))
				((>= I N) A))))
      (FUNCTION (LAMBDA (N) (* N (1- N) 1/2))))

Kudos to the Scheme community for elucidating this undecidable
issue some years ago.

    I couldn't get Symbolics CL
    (which I thought WOULD do it), Vax CL, or KCL to put a "constant" into
    read-only space.  What implementations DO put constants in RO space?

Try (set :foo 105) in Symbolics.  It will signal a write in read only error.
That's one kind of constant.

The Symbolics compiler doesn't currently put quoted constants in
compiled functions into read-only space, because it puts the constants
and the code on the same virtual memory page and there is currently a
stupid reason why compiled functions can't normally be put into
read-only space.  I believe it used to make constants read-only a few
years ago.  At some point the stupid reason will be fixed and then all
constants and compiled code will be read-only (and a certain
programmer/technical manager, who I won't name but who will recognize
himself, will have to stop writing self-modifying code!).

I think you'll find that in some systems compiled code and its constants
become read-only during a system building procedure, but not when you
just call the COMPILE or LOAD functions.  Nobody says read-onlyness
of constants is -required- to be enforced.

    ...you are collapsing two behaviors into one special
    form.  A bad idea in this case....

    I hope CLtL would clean-up EQUAL to mean "collapsable" rather than
    subject the poor Lisp novice to yet another slightly-different
    equality predicate.
    
The above two statements don't seem to me to be based on a consistent
philosophy.