www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Templates and the '!'

reply Sha Chancellor <schancel pacific.net> writes:
I just was looking at a piece of code.  And while this is largely my 
problem, I keep reading:

Foo!(int)

as 
Foo not int.

And thinking what on earth? And then remembering oh yeah templates...

Why are we using the ! symbol for templates?  Couldn't we use a | or 

Jul 23 2004
next sibling parent reply Berin Loritsch <bloritsch d-haven.org> writes:
Sha Chancellor wrote:

 I just was looking at a piece of code.  And while this is largely my 
 problem, I keep reading:
 
 Foo!(int)
 
 as 
 Foo not int.
 
 And thinking what on earth? And then remembering oh yeah templates...
 
 Why are we using the ! symbol for templates?  Couldn't we use a | or 

I agree. Foo!(int) Foo|(int) Foo:(int) Foo (int) Foo$(int) Out of the options listed, I think I like the pipe or colon declarator the best. The "!" symbol just naturally maps to "not" in many people's minds.
Jul 23 2004
next sibling parent Daniel Horn <hellcatv hotmail.com> writes:
you've corrupted me!(Human)
now i'll see func!(type) as a not...
never saw it before you said it, and I've been a C++ programmer for ages

Berin Loritsch wrote:
 Sha Chancellor wrote:
 
 I just was looking at a piece of code.  And while this is largely my 
 problem, I keep reading:

 Foo!(int)

 as Foo not int.

 And thinking what on earth? And then remembering oh yeah templates...

 Why are we using the ! symbol for templates?  Couldn't we use a | or 

I agree. Foo!(int) Foo|(int) Foo:(int) Foo (int) Foo$(int) Out of the options listed, I think I like the pipe or colon declarator the best. The "!" symbol just naturally maps to "not" in many people's minds.
Jul 23 2004
prev sibling next sibling parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <cdrvjf$2md5$1 digitaldaemon.com>, Berin Loritsch says...
I agree.

Foo!(int)
Foo|(int)
Foo:(int)
Foo (int)

Foo$(int)

Out of the options listed, I think I like the pipe or colon declarator
the best.
Well, would I be shot down in flames for suggesting this, rather obvious, alternative: Foo<int> Arcane Jill
Jul 23 2004
next sibling parent reply Sean Kelly <sean f4.ca> writes:
In article <cds3re$2qcl$1 digitaldaemon.com>, Arcane Jill says...
In article <cdrvjf$2md5$1 digitaldaemon.com>, Berin Loritsch says...
I agree.

Foo!(int)
Foo|(int)
Foo:(int)
Foo (int)

Foo$(int)

Out of the options listed, I think I like the pipe or colon declarator
the best.
Well, would I be shot down in flames for suggesting this, rather obvious, alternative: Foo<int>
hehe... As for the previous suggestions, the colon is used as a label specifier while pipe is not easily accessible on many international keyboards. From a purely semantic standpoint, "!" correlates much more closely with something like template instantiation than with negation. But then we're all victims of convention ;) I like it how it is. The only other one I sort of like from a visual standpoint is "$" Sean
Jul 23 2004
parent reply Andrew Edwards <ridimz_at yahoo.dot.com> writes:
Sean Kelly wrote:
 In article <cds3re$2qcl$1 digitaldaemon.com>, Arcane Jill says...
 
In article <cdrvjf$2md5$1 digitaldaemon.com>, Berin Loritsch says...

I agree.

Foo!(int)
Foo|(int)
Foo:(int)
Foo (int)

Foo$(int)

Out of the options listed, I think I like the pipe or colon declarator
the best.
Well, would I be shot down in flames for suggesting this, rather obvious, alternative: Foo<int>
hehe... As for the previous suggestions, the colon is used as a label specifier while pipe is not easily accessible on many international keyboards. From a purely semantic standpoint, "!" correlates much more closely with something like template instantiation than with negation. But then we're all victims of convention ;) I like it how it is. The only other one I sort of like from a visual standpoint is "$" Sean
I have to agree with Sean here. ! seems completely natural to me. Then again, I'm a Neophyte "D" Programmer: naturally biased towards all things "D".
Jul 23 2004
parent reply Sha Chancellor <schancel pacific.net> writes:
In article <cds80e$2u3d$1 digitaldaemon.com>, Andrew Edwards says...
Sean Kelly wrote:
 In article <cds3re$2qcl$1 digitaldaemon.com>, Arcane Jill says...
 
In article <cdrvjf$2md5$1 digitaldaemon.com>, Berin Loritsch says...

I agree.

Foo!(int)
Foo|(int)
Foo:(int)
Foo (int)

Foo$(int)

Out of the options listed, I think I like the pipe or colon declarator
the best.
Well, would I be shot down in flames for suggesting this, rather obvious, alternative: Foo<int>
hehe... As for the previous suggestions, the colon is used as a label specifier while pipe is not easily accessible on many international keyboards. From a purely semantic standpoint, "!" correlates much more closely with something like template instantiation than with negation. But then we're all victims of convention ;) I like it how it is. The only other one I sort of like from a visual standpoint is "$" Sean
I have to agree with Sean here. ! seems completely natural to me. Then again, I'm a Neophyte "D" Programmer: naturally biased towards all things "D".
I think I like the $ as the best alternative also. :P Foo$(int) looks good to me.
Jul 23 2004
parent reply "Walter" <newshound digitalmars.com> writes:
"Sha Chancellor" <schancel pacific.net> wrote in message
news:cds920$2us1$1 digitaldaemon.com...
 I think I like the $ as the best alternative also. :P

 Foo$(int) looks good to me.
Yeah, but you'd run afoul of all those folks who want to use $ as a synonym for array.length <g>.
Jul 25 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Walter wrote:

 "Sha Chancellor" <schancel pacific.net> wrote in message
 news:cds920$2us1$1 digitaldaemon.com...
 
I think I like the $ as the best alternative also. :P

Foo$(int) looks good to me.
Yeah, but you'd run afoul of all those folks who want to use $ as a synonym for array.length <g>.
Maybe we should show some international awareness.... FooŁ(int) :-) 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.
Jul 26 2004
next sibling parent "C. Sauls" <ibisbasenji yahoo.com> writes:
Stewart Gordon wrote:
 Maybe we should show some international awareness....
     FooÂŁ(int)
While we're at it, let me propose Foo如(int) -Chris S. -Invironz
Jul 26 2004
prev sibling parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <ce2naq$oi2$3 digitaldaemon.com>, Stewart Gordon says...

Maybe we should show some international awareness....

     FooŁ(int)

:-)

Stewart.
I realise you were joking. (I noticed the smiley!). But in general we should all be aware that this sort of thing is not possible. From the D manual: D source text can be in one of the following formats: * ASCII * UTF-8 * UTF-16BE * UTF-16LE * UTF-32BE * UTF-32LE You'd have to cross ASCII off that list if we were to allow non-ASCII characters in required syntax. Jill
Jul 26 2004
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Arcane Jill wrote:

 In article <ce2naq$oi2$3 digitaldaemon.com>, Stewart Gordon says...
 
 Maybe we should show some international awareness....

     FooŁ(int)

 :-)
<snip>
 You'd have to cross ASCII off that list if we were to allow non-ASCII
characters
 in required syntax.
I realise you realise I was joking. (I noticed the acknowledgement of the smiley!) But a module isn't required to instantiate templates for it to be a valid D module. 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.
Jul 26 2004
prev sibling next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
Arcane Jill wrote:
 In article <cdrvjf$2md5$1 digitaldaemon.com>, Berin Loritsch says...
 
I agree.

Foo!(int)
Foo|(int)
Foo:(int)
Foo (int)

Foo$(int)

Out of the options listed, I think I like the pipe or colon declarator
the best.
Well, would I be shot down in flames for suggesting this, rather obvious, alternative: Foo<int> Arcane Jill
No flames. But there's a good reason why D didn't go down this road. Using < and > for templates invites all kinds of parsing headaches (something about how < and > are already operators). It's Walter's compiler and he wanted to design it so that parsing is easy and fun. By the way, don't you miss the instance keyword? instance Foo(int) iFoo; Ah, the good old days... -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Jul 23 2004
parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <cdsb9n$30ne$1 digitaldaemon.com>, J C Calvarese says...

 Foo<int>
But there's a good reason why D didn't go down this road. 
Using < and > for templates invites all kinds of parsing headaches 
(something about how < and > are already operators). It's Walter's 
compiler and he wanted to design it so that parsing is easy and fun.
Hmmm. Then I think Walter should stop writing <g> in his emails. Jill !(g)
Jul 26 2004
parent reply Berin Loritsch <bloritsch d-haven.org> writes:
Arcane Jill wrote:

 In article <cdsb9n$30ne$1 digitaldaemon.com>, J C Calvarese says...
 
 
Foo<int>
But there's a good reason why D didn't go down this road. 
Using < and > for templates invites all kinds of parsing headaches 
(something about how < and > are already operators). It's Walter's 
compiler and he wanted to design it so that parsing is easy and fun.
Hmmm. Then I think Walter should stop writing <g> in his emails. Jill !(g)
Great one! ROTFLOL
Jul 26 2004
next sibling parent h3r3tic <h3r3tic dev.null> writes:
Berin Loritsch wrote:
 Arcane Jill wrote:
 
 In article <cdsb9n$30ne$1 digitaldaemon.com>, J C Calvarese says...


 Foo<int>
 But there's a good reason why D didn't go down this road. Using < and 
 for templates invites all kinds of parsing headaches (something 
about how < and > are already operators). It's Walter's compiler and he wanted to design it so that parsing is easy and fun.
Hmmm. Then I think Walter should stop writing <g> in his emails. Jill !(g)
Great one! ROTFLOL
Or just at least use <g /> to be compatible with XHTML and not spreading that old HTML bullshit
Jul 26 2004
prev sibling parent reply John Reimer <brk_6502 yahoo.com> writes:
On Mon, 26 Jul 2004 11:24:33 -0400, Berin Loritsch wrote:

 Hmmm. Then I think Walter should stop writing <g> in his emails.
 
 Jill  !(g)
Great one! ROTFLOL
That actually was pretty funny... :-) Does that mean the 'g' stands for "generic," then?
Jul 27 2004
parent reply Berin Loritsch <bloritsch d-haven.org> writes:
John Reimer wrote:

 On Mon, 26 Jul 2004 11:24:33 -0400, Berin Loritsch wrote:
 
 
Hmmm. Then I think Walter should stop writing <g> in his emails.

Jill  !(g)
Great one! ROTFLOL
That actually was pretty funny... :-) Does that mean the 'g' stands for "generic," then?
In netspeak it is supposed to be a synonym for "grin", or basically don't take the comment too seriously.
Jul 27 2004
parent John Reimer <brk_6502 yahoo.com> writes:
On Tue, 27 Jul 2004 17:18:31 -0400, Berin Loritsch wrote:

 
 Does that mean the 'g' stands for "generic," then?
In netspeak it is supposed to be a synonym for "grin", or basically don't take the comment too seriously.
Yes, I realize that. That was just my weak attempt at extending the joke. :-(
Jul 27 2004
prev sibling parent reply Elephant <Elephant_member pathlink.com> writes:
In article <cds3re$2qcl$1 digitaldaemon.com>, Arcane Jill says...
In article <cdrvjf$2md5$1 digitaldaemon.com>, Berin Loritsch says...
I agree.

Foo!(int)
Foo|(int)
Foo:(int)
Foo (int)

Foo$(int)

Out of the options listed, I think I like the pipe or colon declarator
the best.
Well, would I be shot down in flames for suggesting this, rather obvious, alternative: Foo<int> Arcane Jill
Well, would I be shot down in flames for suggesting this, rather obvious,
alternative:
Booo!!! Booooooooooo!!!
Foo!(int)
Foo|(int)
Foo:(int)
Foo (int)

Foo$(int)
Pipe is logical OR no ? , colon is label specifier, the others are ugly, i personally like the !. $ <- scalar <- array Purple Elephant
Jul 23 2004
parent Sha Chancellor <schancel pacific.net> writes:

Pipe is logical OR no ? , colon is label specifier, the others are ugly, i personally like the !. $ <- scalar <- array Purple Elephant
just for email addresses. :P
Jul 23 2004
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Berin Loritsch" <bloritsch d-haven.org> wrote in message
news:cdrvjf$2md5$1 digitaldaemon.com...
 Foo|(int)
 Foo:(int)
These have parsing ambiguity problems.
 Foo (int)

 Foo$(int)
I try to avoid using characters not in the C set.
 The "!" symbol just naturally maps to "not" in many people's minds.
"*" piped to multiply in my mind before I started using C <g>.
Jul 25 2004
parent reply h3r3tic <h3r3tic_member pathlink.com> writes:
I try to avoid using characters not in the C set.
Sorry, but what's the reason ? D is a new language, it's not meant to be compatible with C or C++. Why then restrict to that 30 year old standard ? OT: If I were making up the syntax, I'd make it use Python-like indentation instead of curly braces but that's just the broken CPU in my head ;)
Jul 25 2004
next sibling parent reply Mike Parker <aldacron71 yahoo.com> writes:
h3r3tic wrote:

 Sorry, but what's the reason ? D is a new language, it's not meant to be
 compatible with C or C++. Why then restrict to that 30 year old standard ?
Ah, but it is meant to be compatible with C at the binary level and, to a lesser extent, at the syntax level. The less you deviate from traditional C syntax the easier it is to learn the language.
Jul 26 2004
next sibling parent h3r3tic <h3r3tic dev.null> writes:
Mike Parker wrote:
 h3r3tic wrote:
 
 Sorry, but what's the reason ? D is a new language, it's not meant to be
 compatible with C or C++. Why then restrict to that 30 year old 
 standard ?
Ah, but it is meant to be compatible with C at the binary level and, to a lesser extent, at the syntax level. The less you deviate from traditional C syntax the easier it is to learn the language.
Yet I dont think that foo!(int) is a small deviation from the C syntax. It will seem to C programmers as foo not int. Making it foo (int) for instance (heh, instance...) would make them think "aaaahh, that's something different!" and reading foo at int, pretty much seems logical as a template specialization. AT reads as SPECIALIZED BY in my mind. But again, I don't think I can make anyone/Walter change the current syntax. Yet I still think that if someone is smart enough to learn C, they would be smart enough to learn some syntax changes. Anyway, I hope we'll have implicit specializations so I don't have to use foo!(int) too often
Jul 26 2004
prev sibling parent Berin Loritsch <bloritsch d-haven.org> writes:
Mike Parker wrote:

 h3r3tic wrote:
 
 Sorry, but what's the reason ? D is a new language, it's not meant to be
 compatible with C or C++. Why then restrict to that 30 year old 
 standard ?
Ah, but it is meant to be compatible with C at the binary level and, to a lesser extent, at the syntax level. The less you deviate from traditional C syntax the easier it is to learn the language.
Yes, but the D templating feature is a complete deviation from already. So either use that notation, or if it makes sense, finish the job and use a character not in use in the C language already. WOT: Someone I know and respect (having been in the computing industry for a long time) seriously believes that the creators of C (and Unix) did it as a practical joke. "Why not make things as obtuse as possible?" In the process of making it obtuse, it was also very powerful, and caught on like wildfire (better than using COBOL or assembly for cross platform work). I don't have anything to support his claims, but it is just crazy enough to have some truth to it :)
Jul 26 2004
prev sibling parent Matthias Becker <Matthias_member pathlink.com> writes:
OT: If I were making up the syntax, I'd make it use Python-like indentation
instead of curly braces but that's just the broken CPU in my head ;)
Nope. We wrote a preprocessor for C++ to do just that! int main () cout << "Hello, World\n" way cooler then int main () { cout << "Hello, World\n" }
Jul 26 2004
prev sibling next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
is there any reason it can't be just

Foo(int) a;

?

perhaps it has something to do with it looking a lot like a function.

personally i think Foo!(int) looks like Foo *factorial* int.  i was confused
as hell when i updated D from 0.74 to 0.94 (i forgot about D for a while)
when i saw all these List!(int) and what have you.
Jul 23 2004
parent David Medlock <amedlock nospam.org> writes:
Jarrett Billingsley wrote:
 is there any reason it can't be just
 
 Foo(int) a;
 
 ?
 
 perhaps it has something to do with it looking a lot like a function.
 
 personally i think Foo!(int) looks like Foo *factorial* int.  i was confused
 as hell when i updated D from 0.74 to 0.94 (i forgot about D for a while)
 when i saw all these List!(int) and what have you.
 
 
Maybe the ! is an upside down i for instance? Hehe. The colon looks natural but also looks like a label. The string is unused so it would get my vote as an alternative. Hmmmm arguing syntax and not semantics....flamewar approaching! HEHEHE
Jul 23 2004
prev sibling next sibling parent "C. Sauls" <ibisbasenji yahoo.com> writes:
Sha Chancellor wrote:
 Why are we using the ! symbol for templates?  Couldn't we use a | or 

http://www.digitalmars.com/d/lex.html#specialtokens I'm happy with ! but if it were changed, I'd vote for $ above all. -Chris S. -Invironz
Jul 23 2004
prev sibling next sibling parent Derek <derek psyc.ward> writes:
On Fri, 23 Jul 2004 14:03:21 -0700, Sha Chancellor wrote:

 I just was looking at a piece of code.  And while this is largely my 
 problem, I keep reading:
 
 Foo!(int)
 
 as 
 Foo not int.
 
 And thinking what on earth? And then remembering oh yeah templates...
 
 Why are we using the ! symbol for templates?  Couldn't we use a | or 

Okay, I'll bite too! I still have a mental hiccup when seeing all those '!' symbols embedded inside template instances. Foo(int) is my preference. The ' ' signifying that the next token 'Foo' is a template name and the template is now being instantiated, using 'int' as its argument. However, I haven't been able to grok the whole D template system. Every thime I read the docs and examples, I come away even more confused. I've tried a few times to play with them but it still does not make any sense to me. I guess I'm not sure what problems are trying to be solved by them. But I haven't given up yet. ;-) -- Derek Melbourne, Australia
Jul 23 2004
prev sibling next sibling parent Charles Hixson <charleshixsn earthlink.net> writes:
Sha Chancellor wrote:
 I just was looking at a piece of code.  And while this is largely my 
 problem, I keep reading:
 
 Foo!(int)
 
 as 
 Foo not int.
 
 And thinking what on earth? And then remembering oh yeah templates...
 
 Why are we using the ! symbol for templates?  Couldn't we use a | or 

OK. Well, how about: Foo!!(int) Or even (sorry Walter) Foo!int! I suppose I'm getting too Eiffelish here, and Walter doesn't like separated markers. So I propose The operator should be !! It's name should be _instance_ (just in case we ever want to allow it to be overridden). Spaces before and after it should be optional. So, probably, should be the parens. A type argument is required.
Jul 25 2004
prev sibling parent Matthias Becker <Matthias_member pathlink.com> writes:
Why are we using the ! symbol for templates?  Couldn't we use a | or 

€ isn't used either. I think $ is a pretty stupid symbol.
Jul 26 2004