Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
June 28, 2009 Compiling Templates | ||||
---|---|---|---|---|
| ||||
http://www.reddit.com/r/programming/comments/8wgak/compiling_templates/ |
June 28, 2009 Re: Compiling Templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 |
June 29, 2009 Re: Compiling Templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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
|
June 30, 2009 Re: Compiling Templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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 } |
July 02, 2009 Re: Compiling Templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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?
|
July 02, 2009 Re: Compiling Templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | 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 |
July 02, 2009 Re: Compiling Templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | bearophile Wrote:
> 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.
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.
|
Copyright © 1999-2021 by the D Language Foundation