www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Lazy Variadic Functions

reply bearophile <bearophileHUGS lycos.com> writes:
Can someone tell me what are some possible practical purposes of Lazy Variadic
Functions? They are explained in the D docs
(http://www.digitalmars.com/d/1.0/function.html ), but such docs sometimes
sorely miss various practical usage examples... (I think such docs have to
become a wiki that people can update, etc).

Bye,
bearophile
Aug 08 2008
next sibling parent Wyverex <wyverex.cypher gmail.com> writes:
bearophile wrote:
 Can someone tell me what are some possible practical purposes of Lazy Variadic
Functions? They are explained in the D docs
(http://www.digitalmars.com/d/1.0/function.html ), but such docs sometimes
sorely miss various practical usage examples... (I think such docs have to
become a wiki that people can update, etc).
 
 Bye,
 bearophile

I've used them in some multi threading applications.. import tango.io.Stdout, tango.core.ThreadPool, tango.time.StopWatch, tango.core.Thread; private ThreadPool!() pool; static this() { setPool; } void setPool(uint size = 12) { pool = new ThreadPool!()(size); } //Parallel block******************************************************** // Lazy number of inputs void p_block(void delegate()[] blocks ...) { foreach(blk; blocks) pool.assign(blk); while(pool.activeJobs || pool.pendingJobs) Thread.sleep(0); }//********************************************************************* void main() { int a, b, c, d, e, f, g, h, i, j, k, l; Stdout("testing").newline; StopWatch w1; w1.start; p_block ( { for(a = 0; a < 10003201; ++a){} } , { for(b = 0; b < 80213002; ++b){} } , { for(c = 0; c < 561123423; ++c){} } , { for(d = 0; d < 10003201; ++d){} } , { for(e = 0; e < 80213002; ++e){} } , { for(f = 0; f < 561123423; ++f){} } , { for(g = 0; g < 10003201; ++g){} } , { for(h = 0; h < 80213002; ++h){} } , { for(i = 0; i < 561123423; ++i){} } , { for(j = 0; j < 10003201; ++j){} } , { for(k = 0; k < 80213002; ++k){} } , { for(l = 0; l < 561123423; ++l){} } ); auto t1 = w1.stop; Stdout.format("p_block = {} {} {}", a, b, c).newline; StopWatch w2; w2.start; { for(a = 0; a < 10003201; ++a){} } { for(b = 0; b < 80213002; ++b){} } { for(c = 0; c < 561123423; ++c){} } { for(d = 0; d < 10003201; ++d){} } { for(e = 0; e < 80213002; ++e){} } { for(f = 0; f < 561123423; ++f){} } { for(g = 0; g < 10003201; ++g){} } { for(h = 0; h < 80213002; ++h){} } { for(i = 0; i < 561123423; ++i){} } { for(j = 0; j < 10003201; ++j){} } { for(k = 0; k < 80213002; ++k){} } { for(l = 0; l < 561123423; ++l){} } auto t2 = w2.stop; Stdout.format("linear = {} {} {}", a, b, c).newline; Stdout.format("p_block time: {} Linear time: {} Delta: {}", t1, t2, t2-t1).newline; }
Aug 08 2008
prev sibling next sibling parent reply "Bill Baxter" <wbaxter gmail.com> writes:
On Fri, Aug 8, 2008 at 9:44 PM, bearophile <bearophileHUGS lycos.com> wrote:
 Can someone tell me what are some possible practical purposes of Lazy Variadic
Functions? They are explained in the D docs
(http://www.digitalmars.com/d/1.0/function.html ), but such docs sometimes
sorely miss various practical usage examples... (I think such docs have to
become a wiki that people can update, etc).

Try clicking on the little "comments" button at the upper right of every page of the docs. --bb
Aug 08 2008
parent bearophile <bearophileHUGS lycos.com> writes:
Bill Baxter:
 Try clicking on the little "comments" button at the upper right of
 every page of the docs.

Oh, I did not see that (in more than one year of using those pages), thank you very much :-) Bye, bearophile
Aug 08 2008
prev sibling parent "Bill Baxter" <wbaxter gmail.com> writes:
On Sat, Aug 9, 2008 at 4:16 AM, bearophile <bearophileHUGS lycos.com> wrote:
 Bill Baxter:
 Try clicking on the little "comments" button at the upper right of
 every page of the docs.

Oh, I did not see that (in more than one year of using those pages), thank you very much :-)

Yeh, that's a problem. Nobody does. For some reason those buttons scream out "ignore me!" up there. --bb
Aug 08 2008