Parallel assignment and little else

downs default_357-line at yahoo.de
Wed Sep 24 00:09:57 PDT 2008


Yigal Chripun wrote:
> bearophile wrote:
>> 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
> 
> Multiple assignment as you described would be awesome.
> 
> however, IMHO D doesn't need a parallel_foreach. instead of adding more
> special cases: foreach, foreach_reverse, parallel_foreach, etc I'd
> prefer to remove the above and have a more general syntax.
> regarding parallel and concurrent programming IMHO D needs a general
> solution. I've seen online the presentation of the concur project
> created by Herb Sutter and this is something I'd like to see in D.
> He uses the Active Objects paradigm and I liked both the semantics and
> the syntax.
> He uses the word "active" to denote concurrent execution so adopting
> this to D will produce:
> 
> active { .. } // code inside will be run concurrently on a thread pool
> 
> and in a similar manner:
> 
> active foreach() {} // this would denote parallel foreach

I don't care if it's macros, or whatever, but can we please have a language feature that makes this possible?

statement active(statement st) { return eval("system_threadpool.addTask({ ", st, "}); "); }

active foo;
active { bar; baz; whee; }

This would also allow us to move all versions of foreach into the standard library. And a few other keywords to boot!

 ..

Please? ._.



More information about the Digitalmars-d mailing list