map kinds of Ranges
KennyTM~
kennytm at gmail.com
Mon May 23 23:27:00 PDT 2011
On May 24, 11 11:28, Jonathan M Davis wrote:
> On 2011-05-23 20:18, Mehrdad wrote:
>> On 5/23/2011 7:33 PM, Jonathan M Davis wrote:
>>> Setting aside this particular issue with purity, I would very much
>>> like to see conditional purity implemented (along with conditional
>>> nothrow, conditional @safe, etc.),
>>
>> I'm liking that people are liking the idea. :-)
>> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group
>> =digitalmars.D&artnum=127569
>> <http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&gro
>> up=digitalmars.D&artnum=127569>
>>
>> As much as I like the idea, though, I think a /lot/ of these would be
>> fixed simply with the ability to put metadata/attributes/annotations,
>> instead of introducing new syntax like conditionally_pure, etc. That
>> way, @pure, @nothrow, @safe, etc. could just become attributes that
>> could take in arguments, and it would also simply the syntax of the
>> language a bit, reducing the number of keywords. It would also add one
>> major feature D lacks right now (metadata) that is really helpful in a
>> lot of situations.
>>
>> Thoughts on this?
>
> I believe that the best and most likely to be implemented syntax which has
> been suggested (it was Andrei's idea IIRC) is to simply add optional clauses
> to attributes. So, instead of pure, you'd do pure(condition). If the condition
> is true, the templated function it's on is pure. If the condition is false,
> then the function isn't pure. Don't expect pure to become @pure or nothrow to
> become @nothrow though. I think that at this point, any attribute which is a
> keyword is going to stay one, and any attribute that has @ on the front of it
> is going to stay that way as well.
>
> - Jonathan M Davis
Rather than conditional pure/nothrow/@safe, I suggest simply have a
@functionAttribute(x), such that:
x & 1 <==> pure
x & 2 <==> nothrow
x & 0x30 <==> @safe
so that you only need 1 attribute to explicitly take care of all of the
propagative attributes
import std.traits;
@functionAttribute(functionAttributes!f & functionAttributes!(x.front))
auto front() const {
return f(x.front);
}
instead of having to repeat the same structure 3 times
import std.traits;
@safe(areAllSafe!(f, x.front))
pure(functionAttributes!f & functionAttributes!x.front &
FunctionAttribute.PURE)
nothrow(functionAttributes!f & functionAttributes!x.front &
FunctionAttribute.NOTHROW)
auto front() const {
return f(x.front);
}
More information about the Digitalmars-d
mailing list