code review

Albert van der Horst albert at spenarnc.xs4all.nl
Tue Jul 17 12:54:25 CEST 2012


In article <XnsA0927750022F4duncanbooth at 127.0.0.1>,
Duncan Booth  <duncan.booth at suttoncourtenay.org.uk> wrote:
>Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
>
>> On Fri, 13 Jul 2012 12:30:47 +0000, Albert van der Horst wrote:
>>> The worst of is, of course, = for assignment instead of := . This is
>>> a convention that Python follows, to my dismay.
>>
>> *shrug*
>>
>> The worst is to use = for both equality and assignment, like some
>> BASICs. At least Python does not allow assignment as an expression, so
>> you can't make the typical C error of:
>>
>> if x = y: do_something()  # oops meant x == y
>>
>Technically of course Python doesn't have assignment, it just binds names.
>
>Albert raised the subject of Algol 68 which if I remember correctly used :=
>for assignment and = to bind names (although unlike Python you couldn't
>then re-bind the name to another object in the same scope).

Algol 68 is very particular about this indeed.
For instance they have a whole theory behind
real x;
x := 17.;

This is considered an abbreviation of
ref real x = loc real;
x:= 17;

So x is a reference bound to a freshly generated local real.
You see = and that means you can't ever break that relationship.
On the left side of a := it is required to have a ref something.
Because that generates a pretty clear context, you have considerable
leeway on the right side, that is cast into the something.

real x= 18.;
x := 15.;
is right out.

If you want to rebind something you need a ref which is really
a ref ref. Then you can only switch bindings between different
types. So it is totally different from Python.

I never thought about = in python to mean binding to set it
apart from the Pascal := , instead of being a c-ism.

Still my mathematical mind is bothered about the sequence
( legal in FORTRAN , C Python )
   X = 1   <separator>
   X = 2

Groetjes Albert

>--
>Duncan Booth http://kupuguy.blogspot.com

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list