www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Does anyone like the template syntax "!()" ?

reply Tomás A. Rossi <Tomás_member pathlink.com> writes:
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.

Isn't there an alternative?

Best regards 
Tom
Oct 11 2005
next sibling parent reply "Walter Bright" <newshound digitalmars.com> writes:
"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>.
 I think it's better than C++ angular bracket syntax, but it's still a
little
 ugly. Isn't there an alternative?
It's not perfect, but I don't think there's a better solution.
Oct 11 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
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.
Oct 13 2005
parent "Walter Bright" <newshound digitalmars.com> writes:
"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!
Oct 14 2005
prev sibling next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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 think it's better than C++ angular bracket syntax, but it's still a 
 little
 ugly.
I'm with Walter on this one. That, and by now, !() just screams "template" to me. <> does not.
Oct 11 2005
parent reply Tomás Rossi <Tomás_member pathlink.com> writes:
In article <dihjs7$580$1 digitaldaemon.com>, Jarrett Billingsley says...
"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 think it's better than C++ angular bracket syntax, but it's still a 
 little
 ugly.
I'm with Walter on this one. That, and by now, !() just screams "template" to me. <> does not.
I'm not saying the opposite. I just wonder if there could be a workaround to that syntax as well. I repeat: i like it more than <>, but is !() the best? Thanks Tom
Oct 11 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Wed, 12 Oct 2005 01:20:58 +0000 (UTC), Tomás Rossi  
<Tomás_member pathlink.com> wrote:
 In article <dihjs7$580$1 digitaldaemon.com>, Jarrett Billingsley says...
 "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 think it's better than C++ angular bracket syntax, but it's still a
 little
 ugly.
I'm with Walter on this one. That, and by now, !() just screams "template" to me. <> does not.
I'm not saying the opposite. I just wonder if there could be a workaround to that syntax as well. I repeat: i like it more than <>, but is !() the best?
Yes. Regan p.s. If you have a suggestion as to a different syntax please post it.
Oct 11 2005
parent reply Tomás Rossi <Tomás_member pathlink.com> writes:
In article <opsyiecdxa23k2f5 nrage.netwin.co.nz>, Regan Heath says...
On Wed, 12 Oct 2005 01:20:58 +0000 (UTC), Tomás Rossi  
<Tomás_member pathlink.com> wrote:
 In article <dihjs7$580$1 digitaldaemon.com>, Jarrett Billingsley says...
 "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 think it's better than C++ angular bracket syntax, but it's still a
 little
 ugly.
I'm with Walter on this one. That, and by now, !() just screams "template" to me. <> does not.
I'm not saying the opposite. I just wonder if there could be a workaround to that syntax as well. I repeat: i like it more than <>, but is !() the best?
Yes. Regan p.s. If you have a suggestion as to a different syntax please post it.
Well, you're right on that one. But maybe someone else have a suggestion. I was trying to introduce a subject that is of my interest because that template syntax workaround !() is the only little spot in a really beautiful syntax (enhanced with respect to c++). Greetings Tom
Oct 11 2005
parent JT <jtd514 ameritech.net> writes:
I agree with this - it seems out of place in D. But hey Im getting used 
to it. its really not that big of a deal.


Tomás Rossi wrote:
 that is of my interest because that template syntax workaround !() is the only
 little spot in a really beautiful syntax (enhanced with respect to c++).
 
 Greetings
 Tom
Oct 11 2005
prev sibling next sibling parent reply Sean Kelly <sean f4.ca> writes:
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. 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. Sean
Oct 11 2005
parent reply "John C" <johnch_atms hotmail.com> writes:
"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. requirement for a space between the brackets. Here's a sample of the syntax for parameterised types from different languages: 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

 
Oct 12 2005
next sibling parent Sean Kelly <sean f4.ca> writes:
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. 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
Oct 12 2005
prev sibling next sibling parent reply Ivan Senji <ivan.senji_REMOVE_ _THIS__gmail.com> writes:
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.
Oct 12 2005
parent reply "Walter Bright" <newshound digitalmars.com> writes:
"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.
Oct 14 2005
next sibling parent Ivan Senji <ivan.senji_REMOVE_ _THIS__gmail.com> writes:
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. :)
Oct 14 2005
prev sibling parent BCS <BCS_member pathlink.com> writes:
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) 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.
Oct 14 2005
prev sibling parent reply "Walter Bright" <newshound digitalmars.com> writes:
"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.

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.
Oct 14 2005
parent reply "John C" <johnch_atms hotmail.com> writes:
"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.

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.

 
Oct 15 2005
next sibling parent Georg Wrede <georg.wrede nospam.org> writes:
John C wrote:
 "Walter Bright" <newshound digitalmars.com>
 "John C" <johnch_atms hotmail.com>
 "Sean Kelly" <sean f4.ca>
 <dihdcb$bb$1 digitaldaemon.com>, Tomás A. Rossi
 
 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.

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.
I think the current syntax is good enougn.
Oct 15 2005
prev sibling next sibling parent Sean Kelly <sean f4.ca> writes:
In article <diqgpb$1qje$1 digitaldaemon.com>, John C says...
"Walter Bright" <newshound digitalmars.com> wrote in message 
news:dip1m0$i50$2 digitaldaemon.com...
 <> 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?
A type or an integral constant. Though a must be a type, so there is that. But as one of Walter's primary goals for D was to produce a language that's very easy to parse, why introduce syntax that has known ambiguities?
I'm not dissing D's syntax at all. I just wanted to point out that C++'s 
syntax isn't evil.
True enough. Sean
Oct 15 2005
prev sibling parent reply "Walter Bright" <newshound digitalmars.com> writes:
"John C" <johnch_atms hotmail.com> wrote in message
news:diqgpb$1qje$1 digitaldaemon.com...
 "Walter Bright" <newshound digitalmars.com> wrote in message
 news:dip1m0$i50$2 digitaldaemon.com...
 <> 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?
One major goal of D is to be able to parse the code without needing to consult the symbol table. This makes for both a dramatic simplification of the compiler, and it enables easy creation of third party tools that need to be able to parse the code. Furthermore, b can be a variable in C++ if it is a value parameter.
 I'm not dissing D's syntax at all. I just wanted to point out that C++'s
 syntax isn't evil.
Evil or not, the parsing problems of C++ templates are one reason why it has taken many years for any conforming C++ compilers to appear, and the general lack of 3rd party tools that can correctly parse C++. These concerns were brought up when <> was selected, and the concerns were dismissed. All the predicted downsides of <> have come to pass. There is nothing inherently superior to <>, it doesn't even look good - consider an expression using a mix of iostreams, templates, shift operators, and less/greater than. It's unreadable. I can't see a good reason to repeat the mistake.
Oct 15 2005
parent Tomás Rossi <Tomás_member pathlink.com> writes:
You´re right about not to make the same mistake. As you said, <> has so much
problems and though I like !() better, it´s a shame because it's not a perfect
and beautiful syntax either. But I guess it's all about tastes and I understand
you had not much of a choice. If there were more symbols we could use to write
our programs, that would be bliss. 

Regards
Tom

PS: Sorry for my English, I am a Spanish speaker (from Argentina)... though I do
my best :)

In article <dirh1o$2k4d$2 digitaldaemon.com>, Walter Bright says...
"John C" <johnch_atms hotmail.com> wrote in message
news:diqgpb$1qje$1 digitaldaemon.com...
 "Walter Bright" <newshound digitalmars.com> wrote in message
 news:dip1m0$i50$2 digitaldaemon.com...
 <> 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?
One major goal of D is to be able to parse the code without needing to consult the symbol table. This makes for both a dramatic simplification of the compiler, and it enables easy creation of third party tools that need to be able to parse the code. Furthermore, b can be a variable in C++ if it is a value parameter.
 I'm not dissing D's syntax at all. I just wanted to point out that C++'s
 syntax isn't evil.
Evil or not, the parsing problems of C++ templates are one reason why it has taken many years for any conforming C++ compilers to appear, and the general lack of 3rd party tools that can correctly parse C++. These concerns were brought up when <> was selected, and the concerns were dismissed. All the predicted downsides of <> have come to pass. There is nothing inherently superior to <>, it doesn't even look good - consider an expression using a mix of iostreams, templates, shift operators, and less/greater than. It's unreadable. I can't see a good reason to repeat the mistake.
Tomás A. Rossi
Oct 15 2005
prev sibling next sibling parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
"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) ?
It is unfortunate keyboards don't have another brace set.
 I think it's better than C++ angular bracket syntax, but it's still a 
 little
 ugly.

 Isn't there an alternative?
probably not. The only one that occurs to me is replacing the '!' with a less obtrusive character like '.'. For example Foo.(T) or pkg.mod.class.(Foo,Bar). One advantage (perhaps) of .() over !() is that !( can appear as two tokens and so the lexer can't combine !( into one token while .( is never legal today so the lexer can always make .( a token. This is just thinking off the top of my head so if anyone can think of legal D code where .( is two tokens please correct me.
Oct 11 2005
prev sibling parent Don Clugston <dac nospam.com.au> writes:
Tomás A. Rossi wrote:
 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.
 
 Isn't there an alternative?
 
 Best regards 
 Tom
 
 
Another possibility that's more like C++ is <| and |>. (more typing, but doesn't suffer from the >> problem). There's few related options (syntax holes)... Foo<T> Foo!(T) Foo<|T|> Foo(|T|) Foo{|T|} Foo[|T|] Perhaps the colon could be used. I'm less confident about whether this would conflict with something. Can't be used with <> because of the ?: operator. Foo(:T:) Foo[:T:] -- well, it's an interesting syntax for arrays. Foo{:T:} The first one would mean that smilies would become a token :). I think the old argument that "< > doesn't look much like brackets" doesn't carry much weight with the rise of HTML/XML. But the >> problem is a serious one. It's not a great list to choose from. IMHO, these four are the best of a bad bunch: vector<real> a; vector!(real) b; vector(:real:) c; vector<|real|> d;
Oct 12 2005