digitalmars.D - Changing the template defintion syntax.
- Robert DaSilva (13/13) Dec 15 2007 One thing that has bugged me for a while is the in symmetry of how
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (22/35) Dec 17 2007 I think you're confusing a lot of things here. Changing the syntax isn't...
- Robert DaSilva (11/60) Dec 17 2007 The main reason for the suggestion is the symmetry, I'm just adding
One thing that has bugged me for a while is the in symmetry of how template are defined and used. If template were defined with !() instead of () it would also allow multi-level template to be defined with out the "same name as template" kludge. For example U to!(U)!(T)(T t); And while on the note of to, it would be nice if cast used template syntax (as well as any keyword function that took or returned types (const, invariant, typeof, typeid, etc.)). Also the template keyword could be replace with a generic namespace keyword. We could even let all definitions be templatable T template_variable!(T); I don't know how practicable or use full that would be though.
Dec 15 2007
On Sat, 15 Dec 2007, Robert DaSilva wrote:One thing that has bugged me for a while is the in symmetry of how template are defined and used. If template were defined with !() instead of () it would also allow multi-level template to be defined with out the "same name as template" kludge. For example U to!(U)!(T)(T t);I think you're confusing a lot of things here. Changing the syntax isn't enough to make the static parameters of a functions partially applicable. Also I'm not sure if a change in the syntax is needed. You could achieve the same thing with implicit currying. Another thing is that what you're showing here isn't the only thing that can be done with nested templates. The C++ style "anonymous" parametrization is cleaner in this case, but in D you can also change the declaration type inside the template: template foo(int i) { static if(i == 0) class foo {} else int foo; }And while on the note of to, it would be nice if cast used template syntax (as well as any keyword function that took or returned types (const, invariant, typeof, typeid, etc.)).Why?Also the template keyword could be replace with a generic namespace keyword.What? Templates form a namespace, but that doesn't mean templates are equivalent to namespaces. What would be useful though is to be able to instantiate templates with no parameters or templates with only parameters with default values without using !() syntax. But then, how would one differentiate between template symbol and instantiation.We could even let all definitions be templatable T template_variable!(T); I don't know how practicable or use full that would be though.Huh?
Dec 17 2007
Jari-Matti Mäkelä wrote:On Sat, 15 Dec 2007, Robert DaSilva wrote:The main reason for the suggestion is the symmetry, I'm just adding thinks that would possible with the syntax change.One thing that has bugged me for a while is the in symmetry of how template are defined and used. If template were defined with !() instead of () it would also allow multi-level template to be defined with out the "same name as template" kludge. For example U to!(U)!(T)(T t);I think you're confusing a lot of things here. Changing the syntax isn't enough to make the static parameters of a functions partially applicable. Also I'm not sure if a change in the syntax is needed. You could achieve the same thing with implicit currying.Another thing is that what you're showing here isn't the only thing that can be done with nested templates. The C++ style "anonymous" parametrization is cleaner in this case, but in D you can also change the declaration type inside the template: template foo(int i) { static if(i == 0) class foo {} else int foo; }Consistency.And while on the note of to, it would be nice if cast used template syntax (as well as any keyword function that took or returned types (const, invariant, typeof, typeid, etc.)).Why?I never said they were the same thing. But a templated namespace is equivalent to the current template implementation.Also the template keyword could be replace with a generic namespace keyword.What? Templates form a namespace, but that doesn't mean templates are equivalent to namespaces. What would be useful though is to be able to instantiate templates with no parameters or templates with only parameters with default values without using !() syntax. But then, how would one differentiate between template symbol and instantiation.It would be the same as template template_variable(T) { T template_variable; }We could even let all definitions be templatable T template_variable!(T); I don't know how practicable or use full that would be though.Huh?
Dec 17 2007