gcl-devel
[Top][All Lists]
Advanced

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

[Gcl-devel] Re: side effect free


From: Camm Maguire
Subject: [Gcl-devel] Re: side effect free
Date: 06 Nov 2006 18:16:56 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Greetings!  I agree that no absolute notion of 'side-effect-free'
exists in any language, and the situation is worse in common-lisp.

The spec says that if any of the core functions (exact list to be
determined) of CL are modified, then the consequences are undefined.
I would like to use this to label certain of these functions
'execution-order-side-effect-free'.  

One such example is '+ when considering expressions such as '(+ a b),
where a and b are constant (i.e. unmodified) lexical bindings.  If the
user modifies '+, all bets are off anyway, so I can assume it has its
conventional definition.  (If this is too generous an assumption, we
could attach this 'execution-order-...' property to the compile-time
function itself as opposed to its naming symbol.)  Such repeated '(+ a
b) expressions appear ripe for simplification.  More broadly, the same
should apply for '(+ <expr1> <expr2>) where both subexpressions are
'execution-order-side-effect-free', the simplest example of which are
constant lexical symbol evaluations.

Of course, this property if well-defined can be propagated by the
compiler into output compiled code as well.

I'd really like to use this with expressions like '(car a) -- I can
check that the binding is constant, and that there are no rplaca's in
the scope, and that all called functions taking the binding similarly
have this property (or even all called functions in the scope).  I
think this should be sufficient to move the car up to the binding of
'a and bind the result to a new gensym.

Broadly, any function which leaves the heap (modulo gc calls)
unchanged satisfies this criterion.  Anything that allocates memory,
rplaca, rplacd, setf .... are not 'execution-order-side-effect-free'.

Is such a notion sound?

Take care,

Robert Boyer <address@hidden> writes:

> One problem with what you propose is that Common Lisp does not have, as
> far as I know, which is not saying much, a notion of 'side-effect-free'.
> 
> Which of the 500 or so functions in package CL would you say are side
> effect free for the purposes you have in mind?
> 
> Even 'cons' could affect a 'cons-counter'.  Even 'identity' could affect
> time used.
> 
> In my opinion, the best thing that could happen in this area of GCL
> would be to have a 'compiler adviser' that advises a user about such
> things, along with other things that make for slow code, e.g.,
> insufficiently declared arithmetic operations.
> 
> Bob
> 
> 
> 

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah




reply via email to

[Prev in Thread] Current Thread [Next in Thread]