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


Groups > comp.lang.python > #92092

Re: Can Python function return multiple data?

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'value,': 0.03; 'subject:Python': 0.05; 'sys': 0.05; '*not*': 0.07; 'read-only': 0.07; 'mutable': 0.09; 'unexpected': 0.09; 'cc:addr:python-list': 0.10; 'argument': 0.15; 'value.': 0.15; 'copying.': 0.16; 'echo': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'list)': 0.16; 'value:': 0.16; 'wrote:': 0.16; 'case.': 0.18; 'copied': 0.18; 'passes': 0.18; 'language': 0.19; 'discussion': 0.20; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'minor': 0.22; 'pass': 0.22; 'am,': 0.23; '2015': 0.23; 'demonstrate': 0.23; 'header:In-Reply-To:1': 0.24; 'least': 0.27; 'message- id:@mail.gmail.com': 0.28; 'skip:( 20': 0.28; 'appear': 0.29; 'arrays': 0.29; 'cat': 0.29; 'array': 0.29; 'function': 0.30; 'work.': 0.30; 'e.g.': 0.31; 'fri,': 0.31; 'seconds': 0.31; "can't": 0.32; '"the': 0.32; 'implement': 0.32; 'knows': 0.32; 'skip:p 30': 0.32; "d'aprano": 0.33; 'steven': 0.33; 'though.': 0.33; 'subject:?': 0.34; 'received:google.com': 0.34; 'list': 0.35; 'but': 0.36; 'subject:: ': 0.37; 'say': 0.38; 'means': 0.39; 'test': 0.39; 'performance': 0.39; 'even': 0.61; 'real': 0.61; 'more': 0.62; 'real-world': 0.66; 'skip:$ 10': 0.67; 'million': 0.73; '100': 0.79; 'array();': 0.84; 'chrisa': 0.84; "it'd": 0.84; 'timing.': 0.84; 'to:none': 0.90; 'imagine': 0.96
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:cc :content-type; bh=Y7J4ZVMhzDZWZ5uCgBIDyjdyDwbMf8nsEr/jp1we6Hg=; b=yLifZNnn9Ub59FYEXA5LY2UvBySKHD2m5rmjc/woWHGTpPF9cI9QUfIvOMzpqK4ZZF xhrlyhwdFoRWjOknoT27sUiVfFE4Y3kFfSxE6h7jGIZUrRyzPTKcvyijTZTt+dtIABwq RneRbY2G06LzAT4o7mYObMSawV6z3M0jAkB+izPwN5XXNCqpxnOeroIh6Cuxp91XjYdL OsZJrcPZoqVU4wuUZWBwxZnF38e569RxQaYVdP2Iuc+frgLMWHrIQTfcRpvsxq2mR1Dg 0ymTzKJpT6L0Ik4Yjsl6/KAZNAb6TR6lVpBvXRWgdipZmnlLt+tEh51O+n1lm/nJ72/T AV3g==
MIME-Version 1.0
X-Received by 10.107.160.141 with SMTP id j135mr132990ioe.43.1433454266078; Thu, 04 Jun 2015 14:44:26 -0700 (PDT)
In-Reply-To <557086d6$0$13011$c3e8da3$5496439d@news.astraweb.com>
References <3bbe49da-e989-4a8c-a8a9-75d3a786f508@googlegroups.com> <mailman.85.1433289398.13271.python-list@python.org> <mkn139$6hb$1@r01.glglgl.de> <CAPTjJmqQ339eamz7dBoKP83JA8QB5Z4R67T4anzgy+ZrhiscDg@mail.gmail.com> <mailman.133.1433368610.13271.python-list@python.org> <e43a00ed-2b7d-497c-aa95-e30cbc04c04a@googlegroups.com> <557056f9$0$13009$c3e8da3$5496439d@news.astraweb.com> <87a8wf5z4l.fsf@elektro.pacujo.net> <mkpnqm$gfn$1@reader1.panix.com> <557086d6$0$13011$c3e8da3$5496439d@news.astraweb.com>
Date Fri, 5 Jun 2015 07:44:25 +1000
Subject Re: Can Python function return multiple data?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.178.1433454275.13271.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433454275 news.xs4all.nl 2951 [2001:888:2000:d::a6]:33356
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92092

Show key headers only | View raw


On Fri, Jun 5, 2015 at 3:11 AM, Steven D'Aprano <steve@pearwood.info> wrote:
> You need at least one more test to prove pass by value: you need to
> demonstrate that the value bound to y is copied when passed to the
> function. E.g. pass a mutable value (say, a list) and mutate it inside the
> function. If the list in the outer scope is *not* mutated, then and only
> then can you say it is pass by value.

Minor quibble: This discussion is about semantics, not timing. A
language can use pass-by-value but with optimizations for the
read-only case.

$ cat array_argument.php
<?php
function readonly($arr) {if ($arr[1] != 1) echo "WRONG!\n";}
function readwrite($arr) {$arr[1] = 1;}

$array = array();
//Populate a big array
for ($i=0; $i<1000; ++$i) $array[$i] = $i;

//Now pass it repeatedly as an argument
$start = microtime(1);
for ($i=0; $i<100000000; ++$i) readonly($array);
$i/=1000000;
$t = (microtime(1)-$start);
echo "Read-only: $i million iterations in $t seconds\n";

$start = microtime(1);
for ($i=0; $i<100000; ++$i) readwrite($array);
$i/=1000;
$t = (microtime(1)-$start);
echo "Read-write: $i thousand iterations in $t seconds\n";

$ time php array_argument.php
Read-only: 100 million iterations in 11.251608133316 seconds
Read-write: 100 thousand iterations in 2.6384630203247 seconds

real 0m13.914s
user 0m13.780s
sys 0m0.000s


PHP passes arrays by value, but optimizes away the copy in the
read-only case - which means that array mutations can trigger
unexpected copying. But it's still pass-by-value, even though you can
appear to have the performance of pass-by-object/pass-by-reference.
Conceivably, a language might implement pass-by-value by having a
"shadow" that knows that it's "the same as that array only this one
got changed", although I can't imagine it'd be efficient for
real-world work. It'd still be legitimate pass-by-value though.

ChrisA

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


Thread

Can Python function return multiple data? fl <rxjwg98@gmail.com> - 2015-06-02 14:27 -0700
  Re: Can Python function return multiple data? Joel Goldstick <joel.goldstick@gmail.com> - 2015-06-02 17:35 -0400
  Re: Can Python function return multiple data? sohcahtoa82@gmail.com - 2015-06-02 14:40 -0700
  Re: Can Python function return multiple data? John Gordon <gordon@panix.com> - 2015-06-02 21:40 +0000
  Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-03 09:56 +1000
    Re: Can Python function return multiple data? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2015-06-03 15:56 +0200
      Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-04 07:35 +1000
      Re: Can Python function return multiple data? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-03 22:56 +0100
        Re: Can Python function return multiple data? sohcahtoa82@gmail.com - 2015-06-03 15:28 -0700
          Re: Can Python function return multiple data? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-06-03 21:30 -0400
          Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-04 11:52 +1000
          Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-04 23:47 +1000
            Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-04 17:25 +0300
              Re: Can Python function return multiple data? Grant Edwards <invalid@invalid.invalid> - 2015-06-04 14:37 +0000
                Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-04 18:04 +0300
                Re: Can Python function return multiple data? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-06-04 19:51 -0400
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 03:11 +1000
                Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-04 20:30 +0300
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:37 +1000
                Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 13:30 -0400
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:31 +1000
                Re: Can Python function return multiple data? Grant Edwards <invalid@invalid.invalid> - 2015-06-04 18:38 +0000
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:52 +1000
                Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-05 09:04 +1000
                Re: Can Python function return multiple data? Grant Edwards <invalid@invalid.invalid> - 2015-06-05 02:02 +0000
                Re: Can Python function return multiple data? Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-06-05 09:11 +0200
                Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-05 12:27 +0300
                Re: Can Python function return multiple data? Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-06-05 14:04 +0200
                Re: Can Python function return multiple data? BartC <bc@freeuk.com> - 2015-06-04 21:52 +0100
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 09:13 +1000
                Re: Can Python function return multiple data? BartC <bc@freeuk.com> - 2015-06-05 01:16 +0100
                Re: Can Python function return multiple data? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-05 02:40 +0100
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 11:48 +1000
                Re: Can Python function return multiple data? BartC <bc@freeuk.com> - 2015-06-05 11:06 +0100
                Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-05 07:44 +1000
                Re: Can Python function return multiple data? BartC <bc@freeuk.com> - 2015-06-05 10:51 +0100
            Re: Can Python function return multiple data? ElChino <elchino@cnn.cn> - 2015-06-04 17:37 +0200
              Re: Can Python function return multiple data? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-06-04 19:57 -0400
            Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 13:26 -0400
              Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:16 +1000
                Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 18:59 -0400
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 12:37 +1000
                Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-04 20:16 -0700
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 21:06 +1000
                Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-05 06:29 -0700
                Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-06 07:59 +1000
                Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-05 20:20 -0700
                Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-05 23:28 -0400
                Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-05 22:28 -0700
                Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-06 15:43 +1000
                Lawful != Mutable (was Can Python function return multiple data?) Rustom Mody <rustompmody@gmail.com> - 2015-06-07 08:49 -0700
                Re: Lawful != Mutable (was Can Python function return multiple data?) Chris Angelico <rosuav@gmail.com> - 2015-06-08 02:07 +1000
                Re: Lawful != Mutable (was Can Python function return multiple data?) Rustom Mody <rustompmody@gmail.com> - 2015-06-07 09:20 -0700
                Re: Lawful != Mutable (was Can Python function return multiple data?) Chris Angelico <rosuav@gmail.com> - 2015-06-08 02:34 +1000
                Re: Lawful != Mutable (was Can Python function return multiple data?) Rustom Mody <rustompmody@gmail.com> - 2015-06-20 18:59 -0700
                Re: Lawful != Mutable (was Can Python function return multiple data?) Chris Angelico <rosuav@gmail.com> - 2015-06-21 12:32 +1000
                Re: Lawful != Mutable (was Can Python function return multiple data?) Rustom Mody <rustompmody@gmail.com> - 2015-06-20 19:50 -0700
                Re: Lawful != Mutable (was Can Python function return multiple data?) Laura Creighton <lac@openend.se> - 2015-06-21 11:14 +0200
                Re: Lawful != Mutable (was Can Python function return multiple data?) Ron Adam <ron3200@gmail.com> - 2015-06-21 08:55 -0400
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-07 15:51 +1000
                Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-06 13:49 +1000
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-06 14:50 +1000
                Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-06 15:29 +1000
                Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-05 22:32 -0700
                Re: Can Python function return multiple data? Dave Farrance <df@see.replyto.invalid> - 2015-06-06 07:52 +0100
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-07 15:53 +1000
                Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-05 08:21 -0400
                Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-05 16:37 +0300
                Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-04 19:07 -0700
            Re: Can Python function return multiple data? Michael Torrie <torriem@gmail.com> - 2015-06-04 11:36 -0600
            Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 13:51 -0400
            Re: Can Python function return multiple data? Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-06-04 20:17 +0200
              Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:45 +1000
                Re: Can Python function return multiple data? Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-06-05 08:59 +0200
          Re: Can Python function return multiple data? Michael Torrie <torriem@gmail.com> - 2015-06-04 08:16 -0600
        Re: Can Python function return multiple data? sohcahtoa82@gmail.com - 2015-06-05 11:55 -0700
      Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 01:01 -0400
      Re: Can Python function return multiple data? Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-04 12:34 -0600
      Re: Can Python function return multiple data? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-04 20:16 +0100
  Re: Can Python function return multiple data? Serhiy Storchaka <storchaka@gmail.com> - 2015-06-04 09:56 +0300
  Re: Can Python function return multiple data? fl <rxjwg98@gmail.com> - 2015-06-06 10:57 -0700
    Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-06 21:35 -0700
    Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-07 15:47 +1000
  Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-07 15:33 +1000

csiph-web