digitalmars.D - Template expression
- Pac (5/5) Jul 18 2004 Hello,
- J C Calvarese (8/17) Jul 18 2004 What do you mean by "Template expression"?
- Pac (6/18) Jul 19 2004 of course.
- Sean Kelly (5/5) Jul 19 2004 Sort of. D supports templates so such things are possible, but as D req...
- Norbert Nemec (8/13) Jul 20 2004 What was that talk about? If you mean the recent discussion about vector
- Sean Kelly <sean f4.ca>s (8/21) Jul 20 2004 That's what I meant. And I agree that it might only be a partial replac...
- Stephen Waits (6/9) Jul 19 2004 The thing about it is.. C++ template expressions are a nasty ugly hack.
- Norbert Nemec (18/22) Jul 20 2004 This is not quite right. It is true, that meta-programming in C++ is a d...
- Stephen Waits (10/24) Jul 20 2004 I think I'm correct in saying that it's a "nasty ugly hack". However, I...
- Norbert Nemec (31/50) Jul 21 2004 First, we should try to identify what makes expression templates so ugly...
- Norbert Nemec (21/31) Jul 20 2004 Hi there,
Hello, does D support Templares expression. If yes where may I find some documentation on it ? Best regards Pac
Jul 18 2004
Pac wrote:Hello, does D support Templares expression. If yes where may I find some documentation on it ? Best regards PacWhat do you mean by "Template expression"? Have you tried these links? http://www.digitalmars.com/d/template.html http://www.dsource.org/tutorials/index.php?show_topic=Templates -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Jul 18 2004
In article <cdfnd9$1sr$1 digitaldaemon.com>, J C Calvarese says...Pac wrote:of course. Short example of expression templates in C++ : http://www.cuj.com/documents/s=8232/cuj0303langer/ Best regards PacHello, does D support Templares expression. If yes where may I find some documentation on it ? Best regards PacWhat do you mean by "Template expression"? Have you tried these links?
Jul 19 2004
Sort of. D supports templates so such things are possible, but as D requires explicit type specification this sort of thing is incredibly unwieldy. There has been some talk of optimized expression evaluation which may obviate the need for expression templates, but it's on the "to do" list. Sean
Jul 19 2004
Sean Kelly wrote:Sort of. D supports templates so such things are possible, but as D requires explicit type specification this sort of thing is incredibly unwieldy. There has been some talk of optimized expression evaluation which may obviate the need for expression templates, but it's on the "to do" list.What was that talk about? If you mean the recent discussion about vector expressions: yes, they would eliminate one of the most common uses of expression templates, but they would not be a replacement for expression templates in general. If there were an idea to really replace expression templates in general, I would be really interested in it - even though I doubt that it will be possible.
Jul 20 2004
In article <cdinql$1a3u$1 digitaldaemon.com>, Norbert Nemec says...Sean Kelly wrote:That's what I meant. And I agree that it might only be a partial replacement, though that is contingent on what the solution ends up being :)Sort of. D supports templates so such things are possible, but as D requires explicit type specification this sort of thing is incredibly unwieldy. There has been some talk of optimized expression evaluation which may obviate the need for expression templates, but it's on the "to do" list.What was that talk about? If you mean the recent discussion about vector expressions: yes, they would eliminate one of the most common uses of expression templates, but they would not be a replacement for expression templates in general.If there were an idea to really replace expression templates in general, I would be really interested in it - even though I doubt that it will be possible.Same here. But I think this is something that should probably be delayed until the core language features are pretty well established. I'm personally still hopeful that implicit template type determination may make it in at some point, though I suppose this would be a 2.0 feature as well. Sean
Jul 20 2004
Pac wrote:does D support Templares expression. If yes where may I find some documentation on it ?The thing about it is.. C++ template expressions are a nasty ugly hack. My question is, can we get equivalent performance with an increase in elegance an simplicity in D? The clear answer right now and at least through 1.0 is "NO". --Steve
Jul 19 2004
Stephen Waits wrote:The thing about it is.. C++ template expressions are a nasty ugly hack.This is not quite right. It is true, that meta-programming in C++ is a dirty business. But so far, I know of no other language (except a few experimental ones that never made it out into the real world) that offers a similar functionality. I agree, that in C++, the syntax and a few details are designed suboptimal, but I doubt that the core idea of expression templates can be captured by a simpler technique.My question is, can we get equivalent performance with an increase in elegance an simplicity in D?I strongly doubt it. D templates are different from C++, but they share a key property: template parameters are untyped. Template instantiation is mostly a textual copy-and-paste operation done by the compiler. A template cannot be compiled on its own. (This is different to languages that offer "parameterized classes" which can be compiled without knowledge of the types used at instantiation.) We may have a cleaner syntax for templates in D, as well as a number of convenient features, but in principle, expression templates will either look similar or be less powerful than in C++. (And here I would prefer the first option!)The clear answer right now and at least through 1.0 is "NO".In this, I agree.
Jul 20 2004
Norbert Nemec wrote:Stephen Waits wrote:I think I'm correct in saying that it's a "nasty ugly hack". However, I agree, the functionality has yet to be reproduced in a language other than C++. My idea is that, given what we've learned with C++ in the past decade, perhaps now we can achieve the same functionality, without it being a "nasty ugly hack". Think it's possible? Or am I overly optimistic?The thing about it is.. C++ template expressions are a nasty ugly hack.This is not quite right. It is true, that meta-programming in C++ is a dirty business. But so far, I know of no other language (except a few experimental ones that never made it out into the real world) that offers a similar functionality. I agree, that in C++, the syntax and a few details are designed suboptimal, but I doubt that the core idea of expression templates can be captured by a simpler technique.We may have a cleaner syntax for templates in D, as well as a number of convenient features, but in principle, expression templates will either look similar or be less powerful than in C++. (And here I would prefer the first option!)I too will take performance, and functionality, over any syntax. In my work it's a major priority. --Steve
Jul 20 2004
Stephen Waits wrote:Norbert Nemec wrote:First, we should try to identify what makes expression templates so ugly in C++. I think, the basic concept of them should be kept in D. It certainly is not a simple concept, but meta-programming just is an advanced subject, so one should not hope for a simple solution. The problem therefore are not the expression templates, but more fundamental: the meta-language in C++. Looking closely, this meta-language is a purely functional language which is executed at compile-time. It handles types and constant values. The "functions" of this language are the templates (taking types and constants as parameters and "returning" types and constants through the content that can be accessed from outside) The problem in C++ is this language, which was actually found by accident and which is ugly to program, ugly to debug and inefficient to execute (resulting in extremely long compile times for et-programs) What we can do in D is to try to improve and clean up this language. Most of it is already given by the mechanism of templates. The concept already is very similar to that of C++, so it is too late already for going completely different direction, but there is still a lot of room left for improvement. A few ideas: * allowing function calls in constant expressions (restricted to pure functions with only constant arguments) - the compiler would have to be able to identify pure functions (no side-effects, no access to anything besides the arguments) but that should be possible without changes to the language. * compile-time flow control - basically, a compile-time "if" extending the idea of "version", it should take any constant boolean argument, be allowed outside of functions and not open a new namespace. * string handling at compile time * identifier <-> string <-> integer conversion at compile-time * maybe most advanced: "list"-handling at compile time Anyhow, all of this is, of course far beyond 1.0 ...Stephen Waits wrote:I think I'm correct in saying that it's a "nasty ugly hack". However, I agree, the functionality has yet to be reproduced in a language other than C++. My idea is that, given what we've learned with C++ in the past decade, perhaps now we can achieve the same functionality, without it being a "nasty ugly hack". Think it's possible? Or am I overly optimistic?The thing about it is.. C++ template expressions are a nasty ugly hack.This is not quite right. It is true, that meta-programming in C++ is a dirty business. But so far, I know of no other language (except a few experimental ones that never made it out into the real world) that offers a similar functionality. I agree, that in C++, the syntax and a few details are designed suboptimal, but I doubt that the core idea of expression templates can be captured by a simpler technique.
Jul 21 2004
Hi there, looking at your later comments, I find that you mean "expression templates". Actually, these are not just one feature, but a collection of features in C++ that work together allowing a certain way of programming. Most of these features are present in D as well. Templates in D are conceptually different from C++ templates, but they should allow mostly everything that can be done in C++. Considering the complexity of the C++ template mechanism, it will probably need some more investigation to find out whether D templates really capture all aspects, but I'm pretty confident about this. The only major point lacking for expression template programming, though, is implicit instantiation of function templates. This has been a reason for debate for some time now. It will most certainly not be part of D 1.0, but I have little doubt that one day, Walter will give in to the fact that without implicit instantiation, things like expression templates are just impossible. So, the short answer to your question: No, not at the moment, but hopefully, yes, in the future. Ciao, Nobbi Pac wrote:Hello, does D support Templares expression. If yes where may I find some documentation on it ? Best regards Pac
Jul 20 2004