Conditional purity

Simen kjaeraas simen.kjaras at gmail.com
Sun Jul 25 07:10:08 PDT 2010


bearophile <bearophileHUGS at lycos.com> wrote:

> Simen kjaeraas:
>> This is fairly simple currently:
[snip]
> Do you mean code like this (this doesn't work yet)?
[snip]

Yeah.


> I suggest all people in all D newsgroups, to write code that runs, not  
> uncompilable snippets. All errors in the last Walter's talk can be  
> avoided in few minutes running the code. In Python newsgroups 90% of the  
> code snippets are run before they are shown to people.

Of course. But not always does time allow us such excesses. :p


>> In cases
>> like this, I long for some features of the C preprocessor, which would
>> be able to insert any kind of code wherever it wants.
>
> It's much better to look for more clean solutions.

That was kinda my point. :p


>> This feature request, and Steve's problems with final (in
>> std.pattern..mixin temptes..std.concurrency), makes me think there
>> should be some way to specify all (or at least most) such conditionally.
>> There seems to be a real need for it.
>
> A silly idea to add or not add an attribute:
> import std.traits: IF = Select;
> IF!(isPure!TF, @pure, @nothing) int[] map(TF)(TF func, int[] array) {...}

I'd be fine with something like that. Or (Inspiration taken from template
constraints):

( @pure if ( isPure!TF ) ) ( @nothrow if ( isNothrow!TF ) ) int[]
map(TF)(TF func, int[] array) {...}

-- 
Simen


More information about the Digitalmars-d mailing list