What is a type error?

Joe Marshall eval.apply at gmail.com
Thu Jul 13 18:07:08 EDT 2006


Marshall wrote:
>
> Consider the following Java fragment:
>
> void foo() {
>   int i = 0;
>   int j = 0;
>
>   // put any code here you want
>
>   j = 1;
>   i = 2;
>   // check value of j here. It is still 1, no matter what you filled in
> above.
>   // The assignment to i cannot be made to affect the value of j.
>
> }

True, but you have hidden the pointers.  Semantically, the identifiers
i and j refer not to integers but to locations that hold integers.  The
assignment modifies the location.

> Those two local primitive variables cannot be made to have the same
> identity. But you can update them, so this is an example of mutability
> without the possibility of identity.

The identity is temporal:  You use the same variable name at two
different times.  Do you intend for the second `i' to mean the same
variable as the first `i'?




More information about the Python-list mailing list