October 12, 2005
"Sean Kelly" <sean@f4.ca> wrote in message news:dihkfp$5s5$1@digitaldaemon.com...
> In article <dihdcb$bb$1@digitaldaemon.com>, Tomás A. Rossi says...
>>
>>Does anyone like the template syntax Foo!(T) ?
>>I think it's better than C++ angular bracket syntax, but it's still a
>>little
>>ugly.
>
> Overall, I think it's fairly intuitive in that it mimics function call
> syntax.
> And it's better than <>, as nested tempate terminators (ie. >>) cause
> problems.

Surely it's problematic only in terms of parsers being unable to distinquish between the termination of a template definition and a right-shift operator. C# and Java both overcame this, and C++0x will probably remove the requirement for a space between the brackets.

Here's a sample of the syntax for parameterised types from different languages:

C# 2.0:                  class Vector<T>
Eiffel:                     class Vector[T]
VB.NET 2.0:         Class Vector(Of T)
Sather:                  class Vector{T}
O'Caml:                 class ['T] ref Vector

Variations on a theme. They tend to use some form of paired braces, but even that's not really a requirement for a parameterised syntax. For example, the following is not inconceivable:

class Vector->T {...}

(Actually just an excuse to find a purpose for C++'s pointer operator.)

> Templates are one of the things I like best about D.  They're both more
> powerful
> and more elegant than their C++ counterpart, lack of implicit
> instantiation
> notwithstanding.

Implicit instantiation is something D sorely needs. Either that, or some form of duck typing (yes, in a statically-typed language).

var vec = new Vector!(T);

>
>
> Sean
>
> 


October 12, 2005
In article <diioe0$11fh$1@digitaldaemon.com>, John C says...
>
>"Sean Kelly" <sean@f4.ca> wrote in message news:dihkfp$5s5$1@digitaldaemon.com...
>> In article <dihdcb$bb$1@digitaldaemon.com>, Tomás A. Rossi says...
>>>
>>>Does anyone like the template syntax Foo!(T) ?
>>>I think it's better than C++ angular bracket syntax, but it's still a
>>>little
>>>ugly.
>>
>> Overall, I think it's fairly intuitive in that it mimics function call
>> syntax.
>> And it's better than <>, as nested tempate terminators (ie. >>) cause
>> problems.
>
>Surely it's problematic only in terms of parsers being unable to distinquish between the termination of a template definition and a right-shift operator. C# and Java both overcame this, and C++0x will probably remove the requirement for a space between the brackets.

It will.  But this is a problem C++ was sort of backed into because it confused too maky people the old way.  So why create ambiguities if you don't have to? I'll admit that the <> template syntax seems natural, as the angle braces are commonly used for replacement grammars (BNF and such), but I've found no loss of clarity with the D syntax.  The '!' seems a natural fit anyway as it's an imperative signifier.


Sean


October 12, 2005
John C wrote:
> 
> Implicit instantiation is something D sorely needs. Either that, or some form of duck typing (yes, in a statically-typed language).
> 
> var vec = new Vector!(T);
>

Yes, this would be really usefull, and has been suggested many, many
times.
October 13, 2005
Walter Bright wrote:
> "Tomás A. Rossi" <Tomás_member@pathlink.com> wrote in message
> news:dihdcb$bb$1@digitaldaemon.com...
>> Does anyone like the template syntax Foo!(T) ?
> 
> I do <g>.
!(snip)

Don't you mean

I do !(g).

?

:-)

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:- C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on the 'group where everyone may benefit.
October 14, 2005
"Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:diltki$1ku9$1@digitaldaemon.com...
> Walter Bright wrote:
> > "Tomás A. Rossi" <Tomás_member@pathlink.com> wrote in message news:dihdcb$bb$1@digitaldaemon.com...
> >> Does anyone like the template syntax Foo!(T) ?
> >
> > I do <g>.
> !(snip)
>
> Don't you mean
>
> I do !(g).
>
> ?
>
> :-)

Ouch!


October 14, 2005
"John C" <johnch_atms@hotmail.com> wrote in message news:diioe0$11fh$1@digitaldaemon.com...
> "Sean Kelly" <sean@f4.ca> wrote in message news:dihkfp$5s5$1@digitaldaemon.com...
> > In article <dihdcb$bb$1@digitaldaemon.com>, Tomás A. Rossi says...
> >>
> >>Does anyone like the template syntax Foo!(T) ?
> >>I think it's better than C++ angular bracket syntax, but it's still a
> >>little
> >>ugly.
> >
> > Overall, I think it's fairly intuitive in that it mimics function call
> > syntax.
> > And it's better than <>, as nested tempate terminators (ie. >>) cause
> > problems.
>
> Surely it's problematic only in terms of parsers being unable to
distinquish
> between the termination of a template definition and a right-shift
operator.

There's also distinguishing between a less than and greater than operator.

> C# and Java both overcame this,

I disagree, since both support only very limited template forms.

> and C++0x will probably remove the
> requirement for a space between the brackets.

<> will always have parsing problems, and although one might be able to shift around where the seams show, it's still there. For example:

    a < b > * p;

Is it:
    (a<b>) * (p)
or:
    (a < b) > (*p)
?

!() has no parsing ambiguities.


October 14, 2005
"Ivan Senji" <ivan.senji_REMOVE_@_THIS__gmail.com> wrote in message news:dijjrp$1u17$1@digitaldaemon.com...
> John C wrote:
> >
> > Implicit instantiation is something D sorely needs. Either that, or some form of duck typing (yes, in a statically-typed language).
> >
> > var vec = new Vector!(T);
>  >
>
> Yes, this would be really usefull, and has been suggested many, many times.

It'll happen.


October 14, 2005
Walter Bright wrote:
> "Ivan Senji" <ivan.senji_REMOVE_@_THIS__gmail.com> wrote in message
> news:dijjrp$1u17$1@digitaldaemon.com...
> 
>>John C wrote:
>>
>>>Implicit instantiation is something D sorely needs. Either that, or some
>>>form of duck typing (yes, in a statically-typed language).
>>>
>>>var vec = new Vector!(T);
>>
>> >
>>
>>Yes, this would be really usefull, and has been suggested many, many
>>times.
> 
> 
> It'll happen.
> 

Great news. That is why people stay around D, not only is it great but also getting better. :)
October 14, 2005
In article <dip1m1$i50$3@digitaldaemon.com>, Walter Bright says...
>
>
>"Ivan Senji" <ivan.senji_REMOVE_@_THIS__gmail.com> wrote in message news:dijjrp$1u17$1@digitaldaemon.com...
>> John C wrote:
>> >
>> > Implicit instantiation is something D sorely needs. Either that, or some
>>
>> Yes, this would be really usefull, and has been suggested many, many times.
>
>It'll happen.
>
>


I know this is a tall order but...

How about allow operations on templates to define there type with respect to there inputs. As an example, say we have a template with a value parameters defining a struct and we want the return type of a multiplication of two such struct to have a value parameters equal to the sum of the parameters of the operands. This could be done something like this:

#template T (int i)
#{
#    struct T
#    {
#        int v;
#
#    // typeof( T!(i)*T!(j) ) == typeof( T!(i+j) )
#
#        T!(i+j) opMul( T!(j) b)
#        {
#            T!(i+j) ret;
#            ret.v = v*b.b;
#            retrun ret;
#        }
#    }
#}


One actual use of the would be a Unit type that allows things like the division of distance by time and return velocity. The exponents of the various dimensions of measurement could be carried as value parameters and operated on appropriately.


October 15, 2005
"Walter Bright" <newshound@digitalmars.com> wrote in message news:dip1m0$i50$2@digitaldaemon.com...
>
> "John C" <johnch_atms@hotmail.com> wrote in message news:diioe0$11fh$1@digitaldaemon.com...
>> "Sean Kelly" <sean@f4.ca> wrote in message news:dihkfp$5s5$1@digitaldaemon.com...
>> > In article <dihdcb$bb$1@digitaldaemon.com>, Tomás A. Rossi says...
>> >>
>> >>Does anyone like the template syntax Foo!(T) ?
>> >>I think it's better than C++ angular bracket syntax, but it's still a
>> >>little
>> >>ugly.
>> >
>> > Overall, I think it's fairly intuitive in that it mimics function call
>> > syntax.
>> > And it's better than <>, as nested tempate terminators (ie. >>) cause
>> > problems.
>>
>> Surely it's problematic only in terms of parsers being unable to
> distinquish
>> between the termination of a template definition and a right-shift
> operator.
>
> There's also distinguishing between a less than and greater than operator.
>
>> C# and Java both overcame this,
>
> I disagree, since both support only very limited template forms.
>
>> and C++0x will probably remove the
>> requirement for a space between the brackets.
>
> <> will always have parsing problems, and although one might be able to shift around where the seams show, it's still there. For example:
>
>    a < b > * p;
>
> Is it:
>    (a<b>) * (p)
> or:
>    (a < b) > (*p)
> ?

But in the templated form, b would have to be a type, not a variable (VC++ doesn't find it ambiguous). I guess this isn't evaluated in the parsing phase, but does everything have to be valid to the parser?

I'm not dissing D's syntax at all. I just wanted to point out that C++'s syntax isn't evil.

>
> !() has no parsing ambiguities.
>
>