Specialization/is syntax

Daniel Keep daniel.keep.lists at gmail.com
Fri Oct 19 19:48:08 PDT 2007



Bill Baxter wrote:
> Aarti_pl wrote:
>> -----------
>>
>> BTW: above syntax for normal arrays looks for me not very consistent.
>> In fact it should be:
>> # void parse(T : E[])() {
>> #     writefln("Type: ", T.stringof, " Element type: ", A.stringof);
>> # }
>>
>> and then proposal from Extrawurst would be just logical consequence.
> 
> I agree with you.  T:E[] can be read as "T where T is an E[] for some
> E".  Very logical.  With T:T[] I never can remember if the T I get in
> the function is the type passed in or the type without the [].  It's the
> full type right?  So the :T[] really only means "where T is an array",
> and the reuse of T is just a distractor.  T:array would maybe be more to
> the point.  Oh, no wait, it's the other way isn't it.  The function gets
> the T stripped of [].  Gaaahh!

I've never really had a problem with it.  I think of T:T[] as being
"given the user passed in T[], give me T."  Granted, I know how you
feel; there've been many things in my life that have confused me until I
came up with a good way of remembering them.

> The is() syntax is also very odd
>    if (is(T S : S[])) {
>        // S now an alias of T stripped of its []
>    }
> 
> I think it would be more logical as
>    if (is(S;  T : S[])) {
>        // S now an alias of T stripped of its []
>    }

I do agree that the current syntax is a bit weird, but I can't say I
like your solution.  :3  I look at it, and I can't quite work out what
it's trying to say.

> The S; is reminiscent of the first clause of foreach where you can
> declare new scoped symbols whose meaning is derived from what's on the
> right of the ';'.  So that's read "we're declaring a new S, where S is
> the type such that T is S[].
> 
> I think that would also make things like  is(F Args == function) a bit
> more logical too.
> Currently it looks an awful lot like "Args equals a function" but it
> means we're defining a new Args to be the parameters of the function F?
>  Huh?  Compare with
>      is(Args; F==function)
> "Checking if F is a function and also declaring a new Args whose type is
> deduced from F"
> 
> --bb

I suppose is() and specialisation could use improvement.  I guess I'm
just reticent to make sweeping changes to something that I've gotten
used to.  Plus it means you won't be able to make templates that work in
both D 1.0 and D 2.0!

	-- Daniel


More information about the Digitalmars-d-learn mailing list