which language allows you to change an argument's value?

Scott Gifford sgifford at suspectclass.com
Mon Oct 1 19:28:07 CEST 2007


Summercool <Summercoolness at gmail.com> writes:

> I wonder which language allows you to change an argument's value?

[...]

> What about Java and Perl?

Perl will let you change the value of a passed-in object directly.
Others have already answered about Java.

> is there any way to prevent a function from changing the argument's
> value?

Make a copy of the object, and pass in the copy.

Without making a copy, of the languages I know, C++ comes closest to
supporting an unmodifiable argument passed by reference.  Using a
const reference or const pointer indicates that the reference won't be
changed, but even that can be subverted by the function's author with
casting.

-----Scott.



More information about the Python-list mailing list