Favorite non-python language trick?

NickC ncoghlan at gmail.com
Thu Jun 30 05:21:41 EDT 2005


Steven D'Aprano wrote:
> with colour do begin
> red := 0; blue := 255; green := 0;
> end;
>
> instead of:
>
> colour.red := 0; colour.blue := 255; colour.green := 0;

c = colour
c.red = 0; c.blue = 255; c.green = 0
del c # Not strictly needed, but limits the scope of c

When everything's a reference, the Pascal 'with' syntax doesn't gain
you anything over a single-letter variable name. As I recall, it's
handy in Pascal because record assignment has value semantics rather
than reference semantics.

Cheers,
Nick.




More information about the Python-list mailing list