anything like C++ references?
Duncan Booth
duncan at NOSPAMrcp.co.uk
Wed Jul 16 05:04:17 EDT 2003
owski at hotmail.com (Adam Ruth) wrote in
news:f0f51c80.0307150921.7b6667e2 at posting.google.com:
> 2) C++ makes a strong distinction between the initialization operator,
>=, and the assignment operator, =. Both const and reference variables
> use them differently. To me, that's a really big violation of proper
> 'computer science', because conceptually they're the *same* thing.
> But because of context, C++ makes a distinction. Python has no such
> distinction, initialization and assigment are always the same.
>
> (This is true of all static languages with the concept of a constant,
> and I don't really disagree with it as a valuable idiom, but it is
> inconsistent internally, where Python is consistent. Do any languages
> use a different operator for initialization?)
Yes, Algol68.
My Algol68 is more than rusty, but:
Declare a name 'pi' to represent 3.1415926, i.e. declare a constant:
REAL pi = 3.1415926;
Declare a name 'x' to represent a local variable, and assign it a value:
REF REAL x = LOC REAL;
x := 3.1415926;
Shorthand for the above:
REAL x;
x := 3.1415926;
or even:
REAL x := pi;
Initialisation uses '=', assignment uses ':='. Note that the constant is
defined as a real and initialised with one, but the variable is a reference
to a real and initialised with a storage location. The last example is not
initialising x with the value, it is implicitly initialising x with a
location then assigning the value into that location.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list