Any ideas for lazy evaluation on varaible argument functions?
Reiner Pope
some at address.com
Sat Oct 20 04:44:03 PDT 2007
BCS wrote:
> Reply to Daniel,
>
>
>> Sadly, I don't think there's any way to fix this. The problem is that
>> if you've got IFTI (which is what allows you to omit the explicit
>> template instantiation), the arguments can't be very complex. What
>> you would need is something like this:
>>
>
> What is needed is some way to get at the list of type used and munge
> them before they are pushed into the args list.
>
> I don't think this will work but something like this could be scabbed in
> somehow:
>
> void TFunc(A...)(lazy A : ConvertStatic2Dynamic!(A) a) {...}
>
> somehow the syntax* would have to say that A is the types that the
> function *would* be IFTIed on but just use that for the tuple and then
> I'll tell you what to really use.
I like this, although I don't like the : syntax, since : means
specialization to me, which we aren't doing. I also find that the 'a'
seems to get lost at the end, but I don't have any better suggestions
for this syntax. My alternative syntax which I suggested in "Tuple IFTI
with implicit conversions" has a tuple as the params list, which I think
looks nicer in the above case, but it doesn't work so well for specific
parameters, as it requires ugly indexing by parameter position:
void foo(arglist A)(Wrapper!(A[0]) a) {...}
as opposed to
void foo(A)(A : Wrapper!(A) a) {...}
On second thoughts, I don't mind so much the : syntax.
So I like it.
This would also solve a number of
> other problems like this:
>
> void TFn(T)(T a, T b){...}
> char[] world;
> TFn("hello", world); // woops!
I was not aware of this problem until I tried it out just then. The docs
don't say what it should do in this case. My initial thought was that D
does this wrong: T should simply be expressed as typeof(true ? "hello" :
world), which is char[] in D1.
>
> you could use this:
>
> void TFn(T)(T a, T : T b){...}
>
> to say that only the second arg should be used for ITFI, or even have
> the type derived like in the first case.
This doesn't really solve the problem, as you get stuck when you write
TFn(world, "hello");
If my above solution isn't going to be used, then the following would
also work (with your change)
void TFn(A, B)(A : CommonType!(A, B) a, B : CommonType!(A, B) b) {...}
template CommonType(A, B)
{
alias typeof(true ? A : B) CommonType;
}
-- Reiner
More information about the Digitalmars-d
mailing list