anything like C++ references?

Stephen Horne intentionally at blank.co.uk
Mon Jul 14 20:27:43 EDT 2003


On Mon, 14 Jul 2003 23:38:56 +0000 (UTC), Adam Ruth
<owski at hotmail.com> wrote:

>So, then, what makes a different variable type?  If not different syntax 
>and semantics, what would be the signature?

In the sense in which you said there were three types of variables in
C++, there are no different variable types. Pointer data types are
nothing special compared with any other data type.

Syntax and semantics vary from one data type to another, just as with
the mathematical concept of abstract data types. Nothing wrong with
that. In mathematics, an abstract data type is associated with a set
of values *and* a set of operations.

>Let me see if I understand what you're saying.  Even though C++ 
>variables can have different syntax and semantics (depending sometimes 
>on context), the're all really the same internally and are therefore 
>perfectly consistent and usable.

Its not about implementation details. Its about respecting the binding
of variables to values - a high level concept from mathematics.
Binding of variables to objects is a low level implementation detail
in programming languages.

>  Python variables, on the other hand (
>mutable and immutable) have somewhat different semantics (a debatable 
>point) but identical implementaions (indeed, indistinguishable), but are 
>somehow invalid?  

Yes. BY DEFAULT they do NOT respect the binding of variables to
values.

>You say that there is one gold standard definition for what a variable 
>is.  Yet even though C++ deals with variables in three semantically 
>distinct way, they are somehow all valid within that definition?

C++ does not deal with variables in three semantically distinct ways.
It provides a wide range of data types (including pointer types and
reference types) and, in keeping with the mathematical concept of an
abstract data type, each has both its own set of values and its own
set of operations. The only way in which semantics vary from variable
to variable is in that some of those semantics are tied to the
abstract data type.

And C++ respects the binding of variables to values (unless you write
buggy code). Even when using pointers, the binding of variables to
values is preserved. It is merely that pointer values provide an
indirect way of referencing a store location, or placeholder, which
may be manipulated (ie bound to a different value) using some other
means of identifying that placeholder.

That is, the concept of a placeholder referenced potentially by more
than one variable only becomes an issue if you specifically ask for
it.





More information about the Python-list mailing list