Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'python,': 0.02; 'programmer': 0.03; 'static': 0.04; 'value,': 0.04; 'explicitly': 0.05; '21,': 0.07; 'defaults': 0.07; 'postgresql': 0.07; 'variables': 0.07; 'assumed': 0.09; 'attributes': 0.09; 'funny,': 0.09; 'immutable': 0.09; 'violates': 0.09; 'python': 0.11; 'attribute,': 0.16; 'counter()': 0.16; 'destroyed.': 0.16; 'effect.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inputs': 0.16; 'subroutine': 0.16; 'wrote:': 0.18; '(the': 0.22; 'finally,': 0.24; 'possibly': 0.26; 'header :In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'nature': 0.30; 'message-id:@mail.gmail.com': 0.30; 'too.': 0.31; 'default,': 0.31; 'fri,': 0.33; 'implemented': 0.33; 'johnson': 0.35; 'received:google.com': 0.35; 'object,': 0.36; 'similar': 0.36; 'url:org': 0.36; 'should': 0.36; 'being': 0.38; 'expected': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'simply': 0.61; 'side': 0.67; 'subject:Value': 0.84; 'weaker': 0.84; 'effects.': 0.91; 'rick': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=dSX1BSW+KPjyBISiGqpvPodikbjfB6ecC3XuKrla79U=; b=iltTpy5juFGMsSGgLwRdyy0iIfyyHH4Mmopl/e4om0BehNys327r9OZ83dKqtRe1A/ 7hkXMTR6ox7tC2a/4Bj4giGznmrvUiGTKgmGBAnJfd3QKwjuKpEszKGOEkKml5Ilt4m1 4sP8/vAlHQJP4uj3o/ut+pVOZjQyjUakqhUxxPQY8cqhAj1imW1Kd/EGPvmeFqBrnz2P F3mTqvEpy4bUWuDPto3iF+Ovtjn9Wy++h0qmQ+cYlYyVwbBTZ3zu/1mXToPTte+cxaSg H3/GJwp+MhJs5RwC1xkeB2CnO7UpcLLFw1dDLgQYO4DJtHP5Pjhuz9IEwvRgOFh6HejH e/Cg== MIME-Version: 1.0 X-Received: by 10.58.187.4 with SMTP id fo4mr3385937vec.55.1371742714631; Thu, 20 Jun 2013 08:38:34 -0700 (PDT) In-Reply-To: <2e92b4c7-31be-40d2-a906-ab19f3630dfa@googlegroups.com> References: <7e6361d5-6619-4aaa-adda-8b5f01bde57f@googlegroups.com> <447dd1c6-1bb2-4276-a109-78d7a067b442@d8g2000pbe.googlegroups.com> <2e92b4c7-31be-40d2-a906-ab19f3630dfa@googlegroups.com> Date: Fri, 21 Jun 2013 01:38:34 +1000 Subject: Re: Default Value From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371742717 news.xs4all.nl 15940 [2001:888:2000:d::a6]:41362 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48802 On Fri, Jun 21, 2013 at 12:49 AM, Rick Johnson wrote: > When the subroutine is completed, all inputs and local > variables are expected to be destroyed. If the programmer > wants a return value, he need simply ask. Data persistence > is not a function of subroutines! Funny, C violates your description too. int counter() { static int count; return ++count; } Function defaults in Python, being implemented as attributes on the function object, are very similar in nature to static variables in C. They're constructed once at function creation time, they're available to that function (okay, C doesn't have any concept of "reaching into" a function from the outside, Python does), they out-last any particular execution of that function. > Finally, a subroutine > should never have side effects UNLESS the programmer > explicitly ask for a side effect. Bogus. http://www.postgresql.org/docs/current/static/sql-createfunction.html By default, a function is assumed to have side effects. The programmer/sysadmin has to explicitly ask for PostgreSQL to treat the function as NOT having side effects (the IMMUTABLE attribute, or possibly its weaker cousin STABLE). ChrisA