Default mutable parameters in functions
Roy Smith
roy at panix.com
Fri Apr 4 19:38:20 EDT 2014
In article <mailman.8908.1396653807.18130.python-list at python.org>,
Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Fri, 04 Apr 2014 10:00:25 -0400, random832 at 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".
Problem? I always assumed it was a feature :-)
More information about the Python-list
mailing list