digitalmars.D - Use cases for alias parameters
- Bruno Medeiros (12/12) Nov 13 2007 I was reading the discussion at
- Chris Miller (7/16) Nov 13 2007 me =
- Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= (19/30) Nov 13 2007 You can do all kinds of stuff with types, for example foldr/l, currying,
- Jarrett Billingsley (6/12) Nov 13 2007 This works because a delegate literal is really a reference to an
I was reading the discussion at http://d.puremagic.com/issues/show_bug.cgi?id=1100 , and then it got me thinking: What are the use cases for alias parameters, other than: * parameters that are templates * parameters that are variables ? In particular is there any meaningful use case for: * parameters that are either variables or types ? -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Nov 13 2007
On Tue, 13 Nov 2007 09:12:09 -0500, Bruno Medeiros = <brunodomedeiros+spam com.gmail> wrote:I was reading the discussion at =http://d.puremagic.com/issues/show_bug.cgi?id=3D1100 , and then it got=me =thinking: What are the use cases for alias parameters, other than: * parameters that are templates * parameters that are variables ? In particular is there any meaningful use case for: * parameters that are either variables or types ?What about something that takes either a constant or a variable, = determined by the caller, without code duplication? It is also especiall= y = useful with delegate literals, where this allows inlining.
Nov 13 2007
Bruno Medeiros wrote:I was reading the discussion at http://d.puremagic.com/issues/show_bug.cgi?id=1100 , and then it got me thinking: What are the use cases for alias parameters, other than: * parameters that are templates * parameters that are variables ? In particular is there any meaningful use case for: * parameters that are either variables or types ?You can do all kinds of stuff with types, for example foldr/l, currying, filter, map etc. These are pretty awesome features in my opinion. I'm still hoping we could somehow unify the templates and proposed macros in some way. The undocumented feature Chris mentioned is pretty interesting indeed: template foo(alias bar) { ... } void moose() { foo!({ chicken(); }); ... } Since alias accepts only explicitly defined symbols and for some unknown reason delegate literals, I thought this was a hidden macro system :) It could possibly inline the delegate but it doesn't currently :| Also there are interesting places where alias parameters could be used, e.g. operator overloadings (to avoid extra parameter passing). Extending these could eliminate many cases where you need to use ugly CTFE&mixin trick.
Nov 13 2007
"Jari-Matti Mäkelä" <jmjmak utu.fi.invalid> wrote in message news:fhd1pm$dke$1 digitalmars.com...Since alias accepts only explicitly defined symbols and for some unknown reason delegate literals, I thought this was a hidden macro system :) It could possibly inline the delegate but it doesn't currently :| Also there are interesting places where alias parameters could be used, e.g. operator overloadings (to avoid extra parameter passing). Extending these could eliminate many cases where you need to use ugly CTFE&mixin trick.This works because a delegate literal is really a reference to an implicitly-defined nested function. So you're passing an alias to an automatically-generated symbol name. It works with function literals too: foo!(function void(){ chicken(); });
Nov 13 2007