From: Tin Gherdanarra
Subject: Order of evaluation standardized in Common Lisp?
Date: 
Message-ID: <4djlufF1al1n1U1@individual.net>
A simple experiment reaveals that CL evaluates the parameters
to a function call from left to right:

[3]> (setq *quux* 0)
0
[4]> (list (incf *quux*) (incf *quux*) (incf *quux*))
(1 2 3)

Can I count on this? [Yes]
Or is it implementation-dependent? [No]

-- 
Lisp kann nicht kratzen, denn Lisp ist fluessig

From: Zach Beane
Subject: Re: Order of evaluation standardized in Common Lisp?
Date: 
Message-ID: <m3bqtnffxd.fsf@unnamed.xach.com>
Tin Gherdanarra <···········@gmail.com> writes:

> A simple experiment reaveals that CL evaluates the parameters
> to a function call from left to right:
> 
> [3]> (setq *quux* 0)
> 0
> [4]> (list (incf *quux*) (incf *quux*) (incf *quux*))
> (1 2 3)
> 
> Can I count on this? [Yes]
> Or is it implementation-dependent? [No]

See CLHS section 3.1.2.1.2.3, "Function Forms":

   A function form is evaluated as follows:

   The subforms in the cdr of the original form are evaluated in
-> left-to-right order in the current lexical and dynamic
   environments. The primary value of each such evaluation becomes an
   argument to the named function; any additional values returned by the
   subforms are discarded.

http://www.lispworks.com/documentation/HyperSpec/Body/03_ababc.htm

Zach
From: Pascal Costanza
Subject: Re: Order of evaluation standardized in Common Lisp?
Date: 
Message-ID: <4dk168F1b0rd4U1@individual.net>
Zach Beane wrote:
> Tin Gherdanarra <···········@gmail.com> writes:
> 
>> A simple experiment reaveals that CL evaluates the parameters
>> to a function call from left to right:
>>
>> [3]> (setq *quux* 0)
>> 0
>> [4]> (list (incf *quux*) (incf *quux*) (incf *quux*))
>> (1 2 3)
>>
>> Can I count on this? [Yes]
>> Or is it implementation-dependent? [No]
> 
> See CLHS section 3.1.2.1.2.3, "Function Forms":
> 
>    A function form is evaluated as follows:
> 
>    The subforms in the cdr of the original form are evaluated in
> -> left-to-right order in the current lexical and dynamic
>    environments. The primary value of each such evaluation becomes an
>    argument to the named function; any additional values returned by the
>    subforms are discarded.
> 
> http://www.lispworks.com/documentation/HyperSpec/Body/03_ababc.htm

As a sidenote, it is also considered good practice to keep left-to-right 
evaluation as far as possible in one's own macros, because that's what 
Common Lispers typically expect. If there is a good reason to deviate 
from this rule of thumb, it should be documented.


Pascal

-- 
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
From: Tin Gherdanarra
Subject: Re: Order of evaluation standardized in Common Lisp?
Date: 
Message-ID: <4dl409F1ad5d0U1@individual.net>
Pascal Costanza wrote:
> Zach Beane wrote:
> 
>> Tin Gherdanarra <···········@gmail.com> writes:
>>
>>> A simple experiment reaveals that CL evaluates the parameters
>>> to a function call from left to right:
>>>
>>> [3]> (setq *quux* 0)
>>> 0
>>> [4]> (list (incf *quux*) (incf *quux*) (incf *quux*))
>>> (1 2 3)
>>>
>>> Can I count on this? [Yes]
>>> Or is it implementation-dependent? [No]
>>
>>
>> See CLHS section 3.1.2.1.2.3, "Function Forms":
>>
>>    A function form is evaluated as follows:
>>
>>    The subforms in the cdr of the original form are evaluated in
>> -> left-to-right order in the current lexical and dynamic
>>    environments. The primary value of each such evaluation becomes an
>>    argument to the named function; any additional values returned by the
>>    subforms are discarded.
>>
>> http://www.lispworks.com/documentation/HyperSpec/Body/03_ababc.htm
> 
> 
> As a sidenote, it is also considered good practice to keep left-to-right 
> evaluation as far as possible in one's own macros, because that's what 
> Common Lispers typically expect. If there is a good reason to deviate 
> from this rule of thumb, it should be documented.
> 
> 
> Pascal
> 
Good to know. I'll try to be a good Common Lisp citizen.


-- 
Lisp kann nicht kratzen, denn Lisp ist fluessig
From: Thomas A. Russ
Subject: Re: Order of evaluation standardized in Common Lisp?
Date: 
Message-ID: <ymi7j4aj8mr.fsf@sevak.isi.edu>
Tin Gherdanarra <···········@gmail.com> writes:

> A simple experiment reaveals that CL evaluates the parameters
> to a function call from left to right:
> 
> [3]> (setq *quux* 0)
> 0
> [4]> (list (incf *quux*) (incf *quux*) (incf *quux*))
> (1 2 3)
> 
> Can I count on this? [Yes]

Yes.  It is in the standard.

IIRC, though, what isn't standardized is when the function designator is
resolved to the actual function object.  That would mean that the
following (hideous) code does not have predictable results:

(defun fn (x y) (+ x y))

(defun hack (x)
  (defun fn (x y) (- x y))
  x)


(fn (hack 3) 5)
  =>  -2  or 8 ?




-- 
Thomas A. Russ,  USC/Information Sciences Institute