A Tango Fibers question and a functional programming anecdote.

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Oct 28 09:22:45 PDT 2007


"downs" <default_357-line at yahoo.de> wrote in message 
news:fg1qhp$22m6$1 at digitalmars.com...

> Actually, it started out with a piece of code that looked like this
>
>>
>> Pool.addTask("Load "~info(), &update);
>> Pool.addTask("Prefetch "~info(), &update);
>> Pool.addTask("Prefetch "~info(), &update);

There's an idea for a language feature (off-the-wall and will never get in, 
but regardless!)

class Pool
{
    void addTask(char[][] names..., void delegate() dgs...)
    {
        // names and dgs should be the same length
        // pairs are in names[i] and dgs[i]
    }
}

Pool.addTask("Load " ~ info(), &update, "Prefetch " ~ info(), &update);

Heee.

I don't see, though, why you couldn't do

void addTask(void delegate()[char[]] tasks) { ... }

Pool.addTask(["Load " ~ info() : &update, "Prefetch " ~ info() : &update]);

>
> Clearly, the addTask is redundant here.
> I replaced it with
>
>>
>> [stuple("Load "~info(), &update), stuple...] /map/ &Pool.addTask;
>>
>
> Somebody in IRC pointed out that the stuple was redundant.
> He must feel horrible for indirectly causing this.
>
>>
>> ["Load "~info, ...] /zip/ [&update, ...] /map/ &Pool.addTask;
>>
>
> Then I noticed the info calls were also redundant. It went kinda out of
> control after that. You know the result. :)

Redundancy is not much to worry about, especially if the result of removing 
it is entirely unreadable. 





More information about the Digitalmars-d mailing list