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

SIDE-EFFECT-FREE/STATELESS Functions



   Date: Fri, 13 May 88 01:56:30 PDT
   From: Jon L White <edsel!jonl@labrea.stanford.edu>

   In a more general sense, a user would want to be able to tell the
   compiler that a certain named function has no internal state and that:
      (1) it has no side effects, and
      (2) its value is completely determined by its arguments.
   Thus RANDOM is not side-effect-free, since it updates *random-state*; and 
   while FIND-SYMBOL is side-effect-free, it is not stateless since it is 
   sensitive to the setting of the global variable *package* as well as to 
   the entries in the package database. AREF is both side-effect-free and
   stateless.  

Be careful here.  Lisp has various ideas of equality, so whether a
"value is completely determined by its arguments" has to be qualified
by the type of equality you are talking about.  For example

	(eq (aref some-array 3)
	    (progn (some-function some-array)
		   (aref some-array 3)))

is NOT guaranteed to return T, even though AREF is being given EQL
arguments in both cases.

I think you partially addressed this in the later portion of your
message, but I was uncomfortable with this AREF example you gave.

						barmar