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


Groups > comp.lang.python > #69697

Re: Default mutable parameters in functions

From Dave Angel <davea@davea.name>
Subject Re: Default mutable parameters in functions
Date 2014-04-04 22:21 -0400
Organization news.gmane.org
References <ac388f0b-8951-42af-a94f-33abdb7231e7@googlegroups.com> <lhkuue$m4j$1@ger.gmane.org> <1396620025.10391.102762569.6DD0D52A@webmail.messagingengine.com> <dffuj9p2as99e6q5ej37l95fjsibf5bsv6@4ax.com>
Newsgroups comp.lang.python
Message-ID <mailman.8910.1396664147.18130.python-list@python.org> (permalink)

Show all headers | View raw


Dennis Lee Bieber <wlfraed@ix.netcom.com> Wrote in message:
> On Fri, 04 Apr 2014 10:00:25 -0400, random832@fastmail.us declaimed the
> following:
> 
>>
>>I can't imagine a language that would work that way. For one, it would
>>also imply that passing a value would change the default for future
>>calls even for non-mutable types.
> 
> 	Some early FORTRAN compilers purportedly had problems with, for
> example:
> 
> 	X = 1
> 	call mutant(1)
> 	Y = 1
> 	
> where
> 
> 	subroutine mutant(y)
> 
> 	y = y + 1
> 	return
> 
> meant that Y now held the value of 2 -- that is, literals were stored in
> mutable memory, and since FORTRAN passes by reference, the address of the
> literal is passed, and the assignment changed the "constant".

I can confirm that,  first hand.

In late 60's, CDC 6400, I deliberately wrote code to exploit that.
  Not for production of course.


-- 
DaveA

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


Thread

Default mutable parameters in functions fbicknel@gmail.com - 2014-04-03 11:49 -0700
  Re: Default mutable parameters in functions Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-03 15:32 -0600
  Re: Default mutable parameters in functions Ethan Furman <ethan@stoneleaf.us> - 2014-04-03 14:44 -0700
  Re: Default mutable parameters in functions Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-04-03 20:27 -0400
  Re: Default mutable parameters in functions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-04-04 01:38 +0100
  Re: Default mutable parameters in functions random832@fastmail.us - 2014-04-04 10:00 -0400
    Re: Default mutable parameters in functions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-04 14:34 +0000
      Re: Default mutable parameters in functions Chris Angelico <rosuav@gmail.com> - 2014-04-05 09:47 +1100
  Re: Default mutable parameters in functions Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-04-04 19:23 -0400
    Re: Default mutable parameters in functions Roy Smith <roy@panix.com> - 2014-04-04 19:38 -0400
  Re: Default mutable parameters in functions Dave Angel <davea@davea.name> - 2014-04-04 22:21 -0400

csiph-web