Parallel assignment and little else

bearophile bearophileHUGS at lycos.com
Tue Sep 23 11:43:12 PDT 2008


While "big" and general features like templates, closures and array operations may be very useful in some situations, a programming language becomes handy because of smaller details too, like a slice syntax, etc. So sometimes small things too help. This is a small functionality that I miss from Python, and I may like to see added to D, this is a possible naive syntax:

Swap/Parallel assignment syntax:

a1, a2 = a2, a1;
Equals to:
auto _tmp = a1;
a1 = a2;
a2 = _tmp;


s, t, u = 5, 6, 7;
Equals to:
s = 5;
t = 6;
u = 7;

s, t = s + t, s - t;
Equals to:
auto _tmp = s + t;
t = s - t;
s = _tmp;

If that syntax can't be used, other possibilities exists. Note that generally the comma operator of C looks like a bug-prone operator that isn't that much useful, so I think D may restrict its usage possibilities, to avoid some possible bug sources.

(Note that sometimes in Python it happens the opposite, and I miss things present in D, like the underscore in numbers, like 1_000).

----------------

Once pure functions are present in the D language, then the order of their execution is not important (if their inputs are already fully computed). So the compiler can compute the functions using all the cores of the CPU. This can be done automatically by the compiler (as the Haskell compiled does sometimes), but there can be ways to help it with statements like parallel_foreach() too.

Bye,
bearophile



More information about the Digitalmars-d mailing list