Simplifying templates
BCS
ao at pathlink.com
Sat Nov 29 14:52:58 PST 2008
Reply to Bill,
> On Sun, Nov 30, 2008 at 6:05 AM, dfgh <dfgh at mailinator.com> wrote:
>
>> Warning: this would break existing code.
>>
>> I have an idea for a completely new template syntax that is easier to
>> use and implement. I'll explain it in therms of a hypothetical
>> language called Dscript. Let's start by imagining that Dscript works
>> identically to D 2.0, but it is interpreted and dynamically typed,
>> with eval's (this is not intended to be implemented, and not the main
>> point of this post). Obviously there isn't much of a point to
>> creating two languages with the same syntax, especially since Dscript
>> would be useless for systems programming, contradicting one of the
>> design goals of D. However, there are some things that you can't do
>> if you have static type enforcement. For example, in D this is
>> impossible:
>>
>> template foo(string Type) {
>> invariant foo = eval(Type ~ ".init");
>> }
> Actually something similar is possible in current D with string
> mixins. But they have to be full statements and not expressions.
>
> template foo(string Type) {
> mixin("invariant foo = "~Type~".init;");
> }
this works:
int i = mixin("5");
import std.stdio;
void main(){writef("%d\n", i);}
http://codepad.org/1a14zKsl
> But it might be nice if string mixins worked for expressions too. I
> presume there's some reason Walter didn't make them work as
> expressions, though.
>
More information about the Digitalmars-d
mailing list