Article on Tuples

Bill Baxter dnewsgroup at billbaxter.com
Wed Nov 15 17:05:01 PST 2006


Chris Miller wrote:
> On Wed, 15 Nov 2006 07:53:11 -0500, Bill Baxter <wbaxter at gmail.com> wrote:
> 
>> Seeing this:
>>
>>    alias Tuple!(TP, 8) TR;  // TR is now float,float,3,8
>>    alias Tuple!(TP, TP) TS; // TS is float,float,3,float,float,3
>>
>> makes me really wish the syntax for typedef/alias were:
>>
>>    alias newname = oldname;
>>
>> I always thought the ordering for C++'s typedef was goofy.  I get it 
>> backwards about half the time I think, just because it's basically an 
>> assignment perversely written the other way around from all other 
>> assignments.
>>
>> --bb
> 
> Think of a variable declaration and then put alias/typedef on front of 
> it; ever since I thought of it like this I never made the mistake again.
> 
>    int foo;  // new foo
>    typedef int foo;  // new foo

You probably got the point, but what I meant was that types in D are 
really starting to look just like compile-time variables in a 
compile-time metaprogramming language.  Since they have such a strong 
connection with runtime variables used in D's runtime language, it would 
be nice if the syntax for assigning to those compile-time type variables 
reflected that similarity, instead of clinging to the syntax chosen in 
the 70's by Mr. Ritchie before any of this was even dreamed of.

As far as my messing up the order, I think the big problem is just that 
it's opposite to the order of my thinking.  My thought process is 
usually something like
1) I need to use the type of a slot here.
2) Ugh, what was that type exactly? U delgate(T) or S delegate(U,V)?
3) It would be handy to have a slot_t alias to represent that.
4) ok, I'll make one: [/me types 'alias   slot_t;']
5) *then* I go searching around to figure out what the actual type is to 
fill in there.

So I usually end up /writing/ it in the order  'alias', newname, oldname 
regardless of the order it appears on the screen.

--bb



More information about the Digitalmars-d-announce mailing list