digitalmars.D.learn - Compiling Templates
- Walter Bright (1/1) Jun 28 2009 http://www.reddit.com/r/programming/comments/8wgak/compiling_templates/
- bearophile (7/9) Jun 28 2009 It looks like a quite complex machinery.
- Kagamin (2/4) Jul 02 2009 lisp?
- bearophile (4/8) Jul 02 2009 My experience of Lisp is quite limited. How can you do that with lisp? I...
- Kagamin (2/11) Jul 02 2009 Mine is zero :) From what I heard types in lisp are like any other symbo...
- Joel C. Salomon (4/5) Jun 29 2009 Nice & informative. Now if there were only such a readable description
- Saaa (20/20) Jun 29 2009 Always nice to see the inner workings, thanks.
http://www.reddit.com/r/programming/comments/8wgak/compiling_templates/
Jun 28 2009
Walter Bright:http://www.reddit.com/r/programming/comments/8wgak/compiling_templates/It looks like a quite complex machinery. From the article:But there is a rule in C++ and D that a template with a specific set of arguments can only have one instantiation for the whole program. This means that if the template has already been instantiated with the same arguments, we can simply point to that instantiation and we're done.<Templates are as functions with the "pure" attribute, so the same input gives the same output. Most of the things you can do with templates can be done with functions (even not pure ones!) run at compile-time that are also allowed to use (and receive/return) a type of compile-time variables of type "type" :-) I think this may lead to a language that's cleaner than C++/D-style templates. Bye, bearophile
Jun 28 2009
bearophile Wrote:Most of the things you can do with templates can be done with functions (even not pure ones!) run at compile-time that are also allowed to use (and receive/return) a type of compile-time variables of type "type" :-) I think this may lead to a language that's cleaner than C++/D-style templates.lisp?
Jul 02 2009
Kagamin:bearophile Wrote:Most of the things you can do with templates can be done with functions (even not pure ones!) run at compile-time that are also allowed to use (and receive/return) a type of compile-time variables of type "type" :-) I think this may lead to a language that's cleaner than C++/D-style templates.lisp?My experience of Lisp is quite limited. How can you do that with lisp? I think we are talking about different things. Bye, bearophile
Jul 02 2009
bearophile Wrote:Kagamin:Mine is zero :) From what I heard types in lisp are like any other symbols, no syntactic difference. You should only check you invoke right functions on them.bearophile Wrote:Most of the things you can do with templates can be done with functions (even not pure ones!) run at compile-time that are also allowed to use (and receive/return) a type of compile-time variables of type "type" :-) I think this may lead to a language that's cleaner than C++/D-style templates.lisp?My experience of Lisp is quite limited. How can you do that with lisp? I think we are talking about different things.
Jul 02 2009
Walter Bright wrote:http://www.reddit.com/r/programming/comments/8wgak/compiling_templates/Nice & informative. Now if there were only such a readable description of how exceptions work… —Joel Salomon
Jun 29 2009
Always nice to see the inner workings, thanks. Here a few things that bugged me: Seeing templates as runtime functions, making the whole instantiation thing kind of strange :) Trying to use implicitly deduces parameters for function templates. Writing Foo(d) iso Foo!(int [][])(d). -- template Foo(T: T[]) { void Foo(T array) { writefln(T.stringof); } } void main() { int[] d; Foo!(int [][])(d); //intuitively I wrote int[] at first as that is what I want T to be }
Jun 29 2009