www.digitalmars.com         C & C++   DMDScript  

D - D's template-synthax

reply der_held <der_held_member pathlink.com> writes:
D has a different template-synthax than all other C-like languages (e.g. C++,
future versions of Java and C#, nive, ...). Why? To me the more common synthax
looks a lot nicer:

Foo<Bar> foo;

vs.

Foo!(Bar) foo;
Feb 02 2004
next sibling parent reply "davepermen" <davepermen hotmail.com> writes:
<> is ambiguous to parse.. thats why c++ needs to have vector<shared_ptr<T>
 instead of vector<shared_ptr<T>> for example.

and it was part of the evolution of D's templated that brought it to this.. "der_held" <der_held_member pathlink.com> schrieb im Newsbeitrag news:bvl3cu$3do$1 digitaldaemon.com...
 D has a different template-synthax than all other C-like languages (e.g.

 future versions of Java and C#, nive, ...). Why? To me the more common

 looks a lot nicer:

 Foo<Bar> foo;

 vs.

 Foo!(Bar) foo;

Feb 02 2004
parent reply imr1984 <imr1984_member pathlink.com> writes:
What do you mean "vector<shared_ptr<T>> instead of vector<shared_ptr<T>>" please
explain. 

And I agree, the D template syntax does suck, the C++ way is so much nicer. Oh
well the rest of the languagae is nice. Just my opinion.

In article <bvl3j8$3su$1 digitaldaemon.com>, davepermen says...
<> is ambiguous to parse.. thats why c++ needs to have vector<shared_ptr<T>
 instead of vector<shared_ptr<T>> for example.

and it was part of the evolution of D's templated that brought it to this.. "der_held" <der_held_member pathlink.com> schrieb im Newsbeitrag news:bvl3cu$3do$1 digitaldaemon.com...
 D has a different template-synthax than all other C-like languages (e.g.

 future versions of Java and C#, nive, ...). Why? To me the more common

 looks a lot nicer:

 Foo<Bar> foo;

 vs.

 Foo!(Bar) foo;


Feb 02 2004
parent reply "davepermen" <davepermen hotmail.com> writes:
there's a space in the first one between the two >

vector<shared_ptr<T>     > works
vector<shared_ptr<T>> not

lets see if it works out in this post:D

"imr1984" <imr1984_member pathlink.com> schrieb im Newsbeitrag
news:bvl7rq$ahc$1 digitaldaemon.com...
 What do you mean "vector<shared_ptr<T>> instead of vector<shared_ptr<T>>"

 explain.

 And I agree, the D template syntax does suck, the C++ way is so much

 well the rest of the languagae is nice. Just my opinion.

 In article <bvl3j8$3su$1 digitaldaemon.com>, davepermen says...
<> is ambiguous to parse.. thats why c++ needs to have


 instead of vector<shared_ptr<T>> for example.

and it was part of the evolution of D's templated that brought it to


"der_held" <der_held_member pathlink.com> schrieb im Newsbeitrag
news:bvl3cu$3do$1 digitaldaemon.com...
 D has a different template-synthax than all other C-like languages



C++,
 future versions of Java and C#, nive, ...). Why? To me the more common

 looks a lot nicer:

 Foo<Bar> foo;

 vs.

 Foo!(Bar) foo;



Feb 02 2004
parent reply der_held <der_held_member pathlink.com> writes:
there's a space in the first one between the two >

vector<shared_ptr<T>     > works
vector<shared_ptr<T>> not

Feb 02 2004
next sibling parent reply "davepermen" <davepermen hotmail.com> writes:
does java 1.5 have an overloadable operator >> ?

"der_held" <der_held_member pathlink.com> schrieb im Newsbeitrag
news:bvla8p$e6n$1 digitaldaemon.com...
there's a space in the first one between the two >

vector<shared_ptr<T>     > works
vector<shared_ptr<T>> not

.


Feb 02 2004
parent Matthias Becker <Matthias_member pathlink.com> writes:
does java 1.5 have an overloadable operator >> ?

Operators aren't overloadable, but there is a >> operator.
Feb 02 2004
prev sibling next sibling parent Andy Friesen <andy ikagames.com> writes:
der_held wrote:

there's a space in the first one between the two >

vector<shared_ptr<T>     > works
vector<shared_ptr<T>> not

Java 1.5 can handle Foo<Bar<Quer>> without a whitespace between the two >>.

Right, but: Foo<Bar> baz; looks like a template instantiation, right? What if Foo, Bar, and baz are integers? The meaning becomes TOTALLY different. One of the overt goals of D is to be parsable without being forced to do semantic analysis at the same time. You practically have to code an entire C++ compiler if you want to parse it right. -- andy
Feb 02 2004
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"der_held" <der_held_member pathlink.com> wrote in message
news:bvla8p$e6n$1 digitaldaemon.com...
there's a space in the first one between the two >

vector<shared_ptr<T>     > works
vector<shared_ptr<T>> not

.


So could DMC++ at one point, but I had to take it out to pass the language purity tests <g>. In any case, the foo!(t) parses cleanly with no special cases. foo<t> requires a lot of special case work in the parser, and even then one still winds up with funny rules for odd cases. As far as aesthetics goes, that depends on what you're used to. The < > was ugly to a lot of people when it first came out in C++, but people got accustomed to it over time.
Feb 09 2004
parent reply "davepermen" <davepermen hotmail.com> writes:
it's still ugly to me.. it feels like a html-tag in c

:D

i hate html

"Walter" <walter digitalmars.com> schrieb im Newsbeitrag
news:c096si$1lbu$1 digitaldaemon.com...
 "der_held" <der_held_member pathlink.com> wrote in message
 news:bvla8p$e6n$1 digitaldaemon.com...
there's a space in the first one between the two >

vector<shared_ptr<T>     > works
vector<shared_ptr<T>> not

.


So could DMC++ at one point, but I had to take it out to pass the language purity tests <g>. In any case, the foo!(t) parses cleanly with no special cases. foo<t> requires a lot of special case work in the parser, and even then one still winds up with funny rules for odd cases. As far as

 goes, that depends on what you're used to. The < > was ugly to a lot of
 people when it first came out in C++, but people got accustomed to it over
 time.

Feb 09 2004
next sibling parent reply "davepermen" <davepermen hotmail.com> writes:
actually, the c++ language rules are very stoopid in that case.

you have to be able to specifically parse <Type> and <int> and such tokens
after template tokens, but you are not allowed to specifically parse >>...
thats utterly stupid, really.

"davepermen" <davepermen hotmail.com> schrieb im Newsbeitrag
news:c09vms$2slm$1 digitaldaemon.com...
 it's still ugly to me.. it feels like a html-tag in c

 :D

 i hate html

 "Walter" <walter digitalmars.com> schrieb im Newsbeitrag
 news:c096si$1lbu$1 digitaldaemon.com...
 "der_held" <der_held_member pathlink.com> wrote in message
 news:bvla8p$e6n$1 digitaldaemon.com...
there's a space in the first one between the two >

vector<shared_ptr<T>     > works
vector<shared_ptr<T>> not




.


So could DMC++ at one point, but I had to take it out to pass the


 purity tests <g>. In any case, the foo!(t) parses cleanly with no


 cases. foo<t> requires a lot of special case work in the parser, and


 then one still winds up with funny rules for odd cases. As far as

 goes, that depends on what you're used to. The < > was ugly to a lot of
 people when it first came out in C++, but people got accustomed to it


 time.


Feb 09 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
While it was 10/2/04 7:04 am throughout the UK, davepermen sprinkled 
little black dots on a white screen, and they fell thus:
 actually, the c++ language rules are very stoopid in that case.
 
 you have to be able to specifically parse <Type> and <int> and such tokens
 after template tokens, but you are not allowed to specifically parse >>...
 thats utterly stupid, really.

You'd need to specifically _tokenise_ >> - a whole new concept. That is, unless you really want to explicitly define TempParams ::= TempParams ::= TempParams TempParam ',' TempInst ::= TempName '<' TempParams TempParam '>' TempInst ::= TempName '<' TempParams TempName '<' TempParams '>>' OK, so I'm not sure if this would be a parsing nightmare.... Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Feb 10 2004
parent "News auf Digitalmars.Com" <davepermen hotmail.com> writes:
i know c++ is a parsing nightmare anyways. but fact is, you need to
spefically parse templates anyways. < and > have to be handled specially.
why not >> then, too?

first: Walter stated he has done this in dmc first, so it's definitely not
impossible (and even for him, it felt logical to do it by default).
second: other languages, that adopted it, are able to parse it, too. namely
c# comes to mind (but i'm unsure:D i'm just sure i've seen one).

then again. what's the discussion about? we have D :D

"Stewart Gordon" <smjg_1998 yahoo.com> schrieb im Newsbeitrag
news:c0b050$1ha6$1 digitaldaemon.com...
 While it was 10/2/04 7:04 am throughout the UK, davepermen sprinkled
 little black dots on a white screen, and they fell thus:
 actually, the c++ language rules are very stoopid in that case.

 you have to be able to specifically parse <Type> and <int> and such


 after template tokens, but you are not allowed to specifically parse
...
 thats utterly stupid, really.

You'd need to specifically _tokenise_ >> - a whole new concept. That is, unless you really want to explicitly define TempParams ::= TempParams ::= TempParams TempParam ',' TempInst ::= TempName '<' TempParams TempParam '>' TempInst ::= TempName '<' TempParams TempName '<' TempParams '>>' OK, so I'm not sure if this would be a parsing nightmare.... Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.

Feb 10 2004
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"davepermen" <davepermen hotmail.com> wrote in message
news:c09vms$2slm$1 digitaldaemon.com...
 it's still ugly to me.. it feels like a html-tag in c

The nice thing about the ! is it doesn't overload any other use of !, and so it parses like a champ. I'm a bit surprised ! wasn't used as a binary operator long before. Easy to parse also means things like color syntax highlighting are going to work right without having to build a C++ compiler into the editor.
 :D

 i hate html

LOL. I like HTML's predecessor, RUNOFF, which used dot commands. HTML's main problem is it is so poorly defined (I found 3 different definitions of what a comment in HTML was), that different interpretations of it have produced a bit of a mess.
Feb 13 2004
next sibling parent reply "davepermen" <davepermen hotmail.com> writes:
html has another issue.. redundancy. same for xml.

xml is espencially stupid, because it tries to have "one unified solution to
a specific data representation", while it provides at least 3 for the same
data.

<tag></tag>
is equal to
<tag />

<tag a="." />
is equal to
<tag a="."></tag>

and technically can be done with
<tag><a>.</a></tag> as well


instead of xml, i prefer this own one:

html(
    head(
        title("Title of Page")
    )
    body(
        bgcolour("black")
        font(
            colour("white")
        )

        h1("Hello on my Page")
        p("lele.. not much in here yet")
    )
)

or..

window(
    title("Sure you want to overwrite?")
    button(text("OK") default("true"))
    button(text("Cancel") escape("true"))
)

<tag></tag> is stupid. tag() works much nicer, and shorter:D (and can, if
you add the proper ',' in between, directly get parsed as code, with
function calls in:D)

"Walter" <walter digitalmars.com> schrieb im Newsbeitrag
news:c0itgs$2d6f$1 digitaldaemon.com...
 "davepermen" <davepermen hotmail.com> wrote in message
 news:c09vms$2slm$1 digitaldaemon.com...
 it's still ugly to me.. it feels like a html-tag in c

The nice thing about the ! is it doesn't overload any other use of !, and

 it parses like a champ. I'm a bit surprised ! wasn't used as a binary
 operator long before. Easy to parse also means things like color syntax
 highlighting are going to work right without having to build a C++

 into the editor.

 :D

 i hate html

LOL. I like HTML's predecessor, RUNOFF, which used dot commands. HTML's

 problem is it is so poorly defined (I found 3 different definitions of

 a comment in HTML was), that different interpretations of it have produced

 bit of a mess.

Feb 13 2004
parent reply Sean Kelly <sean ffwd.cx> writes:
davepermen wrote:

 html has another issue.. redundancy. same for xml.
 
 xml is espencially stupid, because it tries to have "one unified solution to
 a specific data representation", while it provides at least 3 for the same
 data.

XML is painfully verbose, but it's not so bad otherwise. I think the attribute vs. contained element distinction is useful for separating identity data from other data. Sean
Feb 13 2004
parent reply "davepermen" <davepermen hotmail.com> writes:
dunno. i just don't like it at all. i hate the <> keys :D they look ugly.
xml looks ugly..

and most the time, if you look at xml, most part of the file are not data,
but xml tag names, and such, filling the whole with useless stuff..

lisp as data format would be great:D

with some simple regexp style definition on how the document has to look

*(window ?(title) *(window)) means a window can contain 0 or 1 title, and
several windows

and then the code, again:D

something like that could be done.. i would prefer it by much..

and when i see xaml being the future, then i think wow, it's a very cool
idea, but urgh, xaml files look UGLY! and i fear:D

"Sean Kelly" <sean ffwd.cx> schrieb im Newsbeitrag
news:c0j5el$2q5t$1 digitaldaemon.com...
 davepermen wrote:

 html has another issue.. redundancy. same for xml.

 xml is espencially stupid, because it tries to have "one unified


 a specific data representation", while it provides at least 3 for the


 data.

XML is painfully verbose, but it's not so bad otherwise. I think the attribute vs. contained element distinction is useful for separating identity data from other data. Sean

Feb 13 2004
parent reply Sean Kelly <sean ffwd.cx> writes:
davepermen wrote:
 
 and most the time, if you look at xml, most part of the file are not data,
 but xml tag names, and such, filling the whole with useless stuff..

Yup. Even with short tag names, 75% of the contents of an XML file is probably descriptive data :) Luckily, you almost never have to actually look at the file, just parse them directly from code. Sean
Feb 13 2004
next sibling parent "davepermen" <davepermen hotmail.com> writes:
this doesn't make it bether. it's a bad fileformat..

"Sean Kelly" <sean ffwd.cx> schrieb im Newsbeitrag
news:c0jj51$eip$1 digitaldaemon.com...
 davepermen wrote:
 and most the time, if you look at xml, most part of the file are not


 but xml tag names, and such, filling the whole with useless stuff..

Yup. Even with short tag names, 75% of the contents of an XML file is probably descriptive data :) Luckily, you almost never have to actually look at the file, just parse them directly from code. Sean

Feb 15 2004
prev sibling parent Derek Parnell <Derek.Parnell No.Spam> writes:
On Fri, 13 Feb 2004 14:29:52 -0800 (02/14/04 09:29:52)
, Sean Kelly <sean ffwd.cx> wrote:

 davepermen wrote:
 and most the time, if you look at xml, most part of the file are not 
 data,
 but xml tag names, and such, filling the whole with useless stuff..

Yup. Even with short tag names, 75% of the contents of an XML file is probably descriptive data :) Luckily, you almost never have to actually look at the file, just parse them directly from code.

Here is someone else's response to XML ... http://users.pandora.be/tommycarlier/smel/index.htm Its trying to be a less-verbose alternative. -- Derek
Feb 15 2004
prev sibling next sibling parent Sean Kelly <sean ffwd.cx> writes:
Walter wrote:
 LOL. I like HTML's predecessor, RUNOFF, which used dot commands. HTML's main
 problem is it is so poorly defined (I found 3 different definitions of what
 a comment in HTML was), that different interpretations of it have produced a
 bit of a mess.

hehe, I think it got that way because non-programmers were writing HTML and constantly screwing up but rather than tell them to learn the language they modified it to suit them. This was definately the case with paragraph tags. Sean
Feb 13 2004
prev sibling next sibling parent Andy Friesen <andy ikagames.com> writes:
Walter wrote:
i hate html

LOL. I like HTML's predecessor, RUNOFF, which used dot commands. HTML's main problem is it is so poorly defined (I found 3 different definitions of what a comment in HTML was), that different interpretations of it have produced a bit of a mess.

HTML would be better if it was Lisp. (not only is the syntax simpler and easier to parse, but you obliviate any distinction between content and 'client side scripting') -- andy
Feb 13 2004
prev sibling parent Juanjo =?ISO-8859-15?Q?=C1lvarez?= <juanjux NOSPAMyahoo.es> writes:
I personally like the ! syntax because it reminds me of the Unix bang:

Unix: #!/bin/bash

"Use bash to run this".

D: TFoo!(int): Use int to run this template.

Walter wrote:

 
 "davepermen" <davepermen hotmail.com> wrote in message
 news:c09vms$2slm$1 digitaldaemon.com...
 it's still ugly to me.. it feels like a html-tag in c

The nice thing about the ! is it doesn't overload any other use of !, and so it parses like a champ. I'm a bit surprised ! wasn't used as a binary operator long before. Easy to parse also means things like color syntax highlighting are going to work right without having to build a C++ compiler into the editor.

Feb 17 2004
prev sibling next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
While it was 2/2/04 8:57 am throughout the UK, der_held sprinkled little 
black dots on a white screen, and they fell thus:
 D has a different template-synthax than all other C-like languages (e.g. C++,
 future versions of Java and C#, nive, ...). Why? To me the more common synthax
 looks a lot nicer:
 
 Foo<Bar> foo;

Presumably because it interferes with context-free syntax. (Foo less than bar) greater than foo.... Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Feb 02 2004
prev sibling parent "C" <dont respond.com> writes:
I like the syntax , C++'s always seemed too wordy.

C
"der_held" <der_held_member pathlink.com> wrote in message
news:bvl3cu$3do$1 digitaldaemon.com...
 D has a different template-synthax than all other C-like languages (e.g.

 future versions of Java and C#, nive, ...). Why? To me the more common

 looks a lot nicer:

 Foo<Bar> foo;

 vs.

 Foo!(Bar) foo;

Feb 02 2004