Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6733

Re: scope of function parameters (take two)

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'parameter': 0.05; 'subject:two': 0.07; 'terry': 0.07; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'similarly,': 0.09; 'subclass': 0.09; 'subject:parameters': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'arrays.': 0.16; 'lisp': 0.16; 'reedy': 0.16; 'retrieves': 0.16; 'subject:function': 0.16; 'sublist': 0.16; 'tuples,': 0.16; 'wrapping': 0.16; 'call.': 0.19; 'programming': 0.19; 'jan': 0.20; 'header:In-Reply-To:1': 0.21; 'objects,': 0.23; 'function': 0.25; 'expect': 0.25; 'parameters': 0.26; 'object': 0.26; 'class': 0.29; 'do.': 0.30; 'objects.': 0.30; 'functional': 0.31; 'header:X-Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'list': 0.33; 'list.': 0.33; 'header :User-Agent:1': 0.35; 'languages': 0.35; 'lists,': 0.36; 'received:org': 0.38; 'creates': 0.38; 'linked': 0.38; 'subject:: ': 0.38; 'subject: (': 0.39; 'perhaps': 0.39; 'header:Mime- Version:1': 0.39; 'to:addr:python.org': 0.39; 'everyone': 0.40; 'really': 0.40; 'easily': 0.60; 'back': 0.63; 'free': 0.63; 'discipline': 0.67
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: scope of function parameters (take two)
Date Tue, 31 May 2011 11:59:21 -0400
References <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> <F4EAD1ED-563D-4D6E-A50C-68308A9F26B7@mcgill.ca> <201105310713.24842.wolfgang@rohdewald.de> <D6671B7A-C8B1-4235-A50F-31D9F2AD7DD7@mcgill.ca>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host rain.gmane.org
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10
In-Reply-To <D6671B7A-C8B1-4235-A50F-31D9F2AD7DD7@mcgill.ca>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2317.1306857576.9059.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 82.94.164.166
X-Trace 1306857577 news.xs4all.nl 49179 [::ffff:82.94.164.166]:36438
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6733

Show key headers only | View raw


On 5/31/2011 2:37 AM, Henry Olders wrote:

> what I want is a function that is free of side effects back through
> the parameters passed in the function call.

You can get that by refraining from mutating parameter objects.
Simple as that.
Just do not expect Python to enforce that discipline on everyone else.
To be really functional, and never mutate objects, do not use Python 
lists, which are arrays. Use linked-list trees, like Lisp languages and 
perhaps others do. One can easily do this with tuples, or a subclass of 
tuples, or a class wrapping tuples.

Linked-lists and functional programming go together because prepending 
to a linked list creates a new object while appending to a Python list 
mutates an existing list. Similarly, popping from a linked list 
retrieves an item and an existing sublist while popping from a Python 
list retrieves and item and mutates the list.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: scope of function parameters (take two) Terry Reedy <tjreedy@udel.edu> - 2011-05-31 11:59 -0400

csiph-web