Conditional Pure?

2011-01-22 Thread %u
I wanted to suggest a feature similar to inout: conditional purity. That is, sometimes a function is pure iff the delegates passed to it are pure, and as of right now, I don't think there's any way to document this other than by overloading the function as a template (which results in lots of code

Re: Conditional Pure?

2011-01-22 Thread bearophile
%u Wrote: > I wanted to suggest a feature similar to inout: conditional purity. That is, > sometimes a function is pure iff the delegates passed to it are pure, I think this is useless. If this is possible, then you just mark every single not-pure function in the program with @conditionally_pure

Re: Conditional Pure?

2011-01-22 Thread %u
> I think this is useless. If this is possible, then you just mark every single not-pure function in the program with @conditionally_pure, and we are back to the beginning. Oh, but that's not what I meant! I meant something like this: int call(TFn)(TFn fn) pure(isPure!(TFn)) if (isCallab

Re: Conditional Pure?

2011-01-22 Thread bearophile
%u: > Oh, but that's not what I meant! I meant something like this: > > int call(TFn)(TFn fn) pure(isPure!(TFn)) > if (isCallable!(TFn)) > { > return fn(5); > } > > This way we specify purity based on a static boolean. I see. I'd like a more general-purpose solution, something t

Re: Conditional Pure?

2011-01-22 Thread %u
> I see. I'd like a more general-purpose solution, something that works with nothrow too and other future attributes too. Funny, that was going to be my next comment. :) The only thing that scares me a bit is that code like this: public(isPublic!(TFn)) static(isStatic!(TFn)) int memoize(TFn)(TFn

Re: Conditional Pure?

2011-01-22 Thread so
nothrow too and other future attributes too. Funny, that was going to be my next comment. :) The only thing that scares me a bit is that code like this: public(isPublic!(TFn)) static(isStatic!(TFn)) int memoize(TFn)(TFn fn) pure(isPure!(TFn)) if (isCallable!(TFn)) { //etc. } A ques

Re: Conditional Pure?

2011-01-22 Thread bearophile
%u: > might turn out a bit unreadable. And, furthermore, I'd *like* to be able to > say > something like "this method returns a shared const value iff the given type > is int > or long" but this won't work with const() or shared() because of their syntax > (you > can't say const(is(T == int))).

Re: Conditional Pure?

2011-01-22 Thread %u
>> Any ideas on how we might be able to get that to work? > @optional_tag(is(T == int) || is(T == long)), const) Ouch... a bit less pretty than I'd hoped (the underscore makes it a bit ugly IMHO). Does it really need to be a tag, though? Why not just: optional(const, is(T == int) || is(T == lon

Re: Conditional Pure?

2011-01-22 Thread Michel Fortin
On 2011-01-22 21:34:52 -0500, %u said: Any ideas on how we might be able to get that to work? @optional_tag(is(T == int) || is(T == long)), const) Ouch... a bit less pretty than I'd hoped (the underscore makes it a bit ugly IMHO). Does it really need to be a tag, though? Why not just: opt

Re: Conditional Pure?

2011-01-22 Thread Jonathan M Davis
On Saturday 22 January 2011 14:41:08 %u wrote: > > I think this is useless. If this is possible, then you just mark every > > single > > not-pure function in the program with @conditionally_pure, and we are back > to the beginning. > > > Oh, but that's not what I meant! I meant something like th