passing by refference

Doug Quale quale1 at charter.net
Thu May 15 22:25:46 EDT 2003


"Donn Cave" <donn at u.washington.edu> writes:

> Quoth Doug Quale <quale1 at charter.net>:
> | "Fredrik Lundh" <fredrik at pythonware.com> writes:
> ... [ quoting account of CLU system (by Barbara Liskov?) ]
> ...
> |>     Objects that do not exhibit time-varying behavior are called
> |>     _immutable_ objects, or constants.  Examples of constants are
> |>     integers, booleans, characters, and strings.  The value of a
> |>     constant object can not be modified.  For example, new strings
> |>     may be computed from old ones, but existing strings do not
> |>     change.  Similarily, none of the integer operations modify the
> |>     integers passed to them as arguments.
> |
> | Same as Scheme and Lisp except that strings are mutable in those languages.
> 
> What does ``the value of a constant object cannot be modified'' mean?
> Is it possible that by "value", the author means the computer data
> represented by the object?

It means there are no operations that can modify the object.  The
object would be modified if any of its observable behavior were
changed.  You could have a language with modifiable integer objects,
for instance, but programming with them would be unecessarily
difficult.  In most languages all scalar values are immutable.  (This
wasn't the case in Fortran where call-by-reference allowed changing
constants with usually undesired effects.)  Scalar values are usually
not precisely defined but the basic idea is that the value can't be
decomposed into smaller parts.  Often the scalar values in a language
are simply listed.

> 
> | This is a description of call-by-value using CLU values (object
> | references).  Note that CLU values used in variable assignment and the
> | binding done by argument passing are the same.  This is the key point.
> 
> Does this key point require that we always expect "value" in the
> context of CLU to mean "object reference"?  Or would you agree that
> this would actually be absurd, except in the context of "call-by-value"
> where we know it must have that meaning because Python passes object
> references, Python is like Scheme and Scheme is call-by-value?

No.  Value here means r-value.  These are the values used on the right
side of assignments or bindings.  The concept of l-values and r-values
makes sense for any programming language that has assignment or
binding.  Curiously, there are languages that have neither. For
example John Backus' FP doesn't even have variables.

I don't think I understand what people think Python values are.  If E
is some Python expression, does it have a different value in a
function call

def f(x):
    ...

f(E)

than it does in an assignment (binding)

x = E

?




More information about the Python-list mailing list