getAttr method
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Fri Feb 8 07:11:23 PST 2008
On Sat, 2 Feb 2008, downs wrote:
> Jarrett Billingsley wrote:
>> "downs" <default_357-line at yahoo.de> wrote in message
>> news:fnvs99$qm$1 at digitalmars.com...
>>
>>> the following code is entirely valid D if you have scrapple.tools
>>> installed:
>>> auto generator = stackthread = (void delegate(int) yield) { int i; while
>>> (true) yield(i++); };
>>> writefln(generator(), generator(), generator());
>>
>> You should start an IODCC. Your code would win every time.
>>
>>
>
> gentoo-pc ~ $ cat test.d; rebuild test.d && echo "---------" && ./test
> // sorry, I left out the indentation because I was in a hurry.
> module test;
> import tools.stackthreads, std.stdio;
>
> void main()
> {
> auto generator = stackthread = (void delegate(int) yield)
> {
> int i;
>
> while (true)
> {
> yield(i);
> i++;
> }
> };
>
> writefln([generator(), generator(), generator()]);
> }
>
> // better? :)
> // --downs
> ---------
> [0,1,2]
> gentoo-pc ~ $
Lazy lists would be much cleaner:
l = [0,1..]
Start = take 3 l // => [0,1,2]
Of course stackthreads have their use too.
More information about the Digitalmars-d
mailing list