Odd Errors

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Oct 2 17:03:48 CEST 2008


On Thu, 02 Oct 2008 18:52:58 +1300, Lawrence D'Oliveiro wrote:

> In message <pan.2008.10.01.09.44.17 at REMOVE.THIS.cybersource.com.au>,
> Steven D'Aprano wrote:
> 
>> On Wed, 01 Oct 2008 22:14:49 +1300, Lawrence D'Oliveiro wrote:
>> 
>>> In message
>>> <1b1ed34d-f386-4389-a7f1-ce68be4e2a14 at k30g2000hse.googlegroups.com>,
>>> Aaron "Castironpi" Brady wrote:
>>> 
>>>> Do you ever want to scream from the rooftops, "'append' operates by
>>>> side-effect!"?
>>> 
>>> No. It's an effect, not a side-effect.
>> 
>> "Side-effect" has the technical meaning in functional languages of any
>> change of state that isn't the creation and return of a function
>> result.
> 
> "Side" means that it happens as the by-product of returning a function
> result. 

Not in functional programming circles. This is what Paul Graham says 
about "side-effect" in Lisp:

"A side-effect is some change to the state of the world that happens as a 
consequence of evaluating an expression."

http://lib.store.yahoo.net/lib/paulgraham/acl2.txt

It is common to refer to procedures (in languages which have them, like 
Pascal) as always operating by side-effect. I remember being taught that 
in Comp Sci classes in the mid 1980s.


> "<list>.append" isn't a function, it's a procedure. Hence the
> modification of the list is the primary effect, not a side effect.

Python doesn't have procedures. list.append is a function, and it returns 
None. That's why hardly a week goes by without somebody failing to read 
the Fine Manual and being surprised why code like this doesn't work:

alist = [1, 2, 3]
alist = alist.append(4)
print len(alist)



-- 
Steven



More information about the Python-list mailing list