On Tuesday, 9 October 2012 at 19:29:34 UTC, F i L wrote:
On Tuesday, 9 October 2012 at 13:28:55 UTC, luka8088 wrote:
Is this at least similar to what you had in mind ?
[ ..code.. ]
Yes, I realized, a bit after I originally posted that, that my
suggestion was already possible if BankType & Logger where
mixin-templates instead of struct/classes. Thanks for the code
example though.
I still think an built-in .codeof/.astof would be nice, but
what D really needs to achieve this in a syntactically pleasing
and powerful way, is 'macro' templates (like Nimrod has) which
work on the AST directly. I doubt this is a major concern ATM
however.
My point of making this example was to show that nothing is
missing in D itself. You just need to be more creative. If you
want to write in a manner more similar to your original example
(by that I mean without mixin templates) you can use classes,
class methods can be turned to delegates with their context
pointer changed before execution, and then you would get the same
effect. Also having such syntax could be very confusing because
someone could introduce some syntax which is very similar to D
but behaves differently and it is embedded in a way that looks
just like a D code.
Also the idea is to have "// generic code" part in some library
and not visible to the *user* so the rest of the code would be
syntactically pleasing. If you check current phobos code, you
will see that there are some examples of using mixins this way.
Please also check the comments on
https://github.com/D-Programming-Language/dmd/pull/953 (if you
haven't done that already).