Specialization/is syntax

Bill Baxter dnewsgroup at billbaxter.com
Fri Oct 19 11:13:41 PDT 2007


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!

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 []
    }

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


More information about the Digitalmars-d-learn mailing list