Default mutable parameters in functions
Dave Angel
davea at davea.name
Fri Apr 4 22:21:01 EDT 2014
Dennis Lee Bieber <wlfraed at ix.netcom.com> Wrote in message:
> 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".
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
More information about the Python-list
mailing list