String mixin syntax sugar

kennytm kennytm at gmail.com
Wed Mar 21 16:54:18 PDT 2012


Mantis <mail.mantis.88 at gmail.com> wrote:
> 21.03.2012 13:35, kennytm пишет:
>> Mantis<mail.mantis.88 at gmail.com>  wrote:
>>> [...]
>>> # identifier statement
>>> 
>> You mean 'declaration'.
> 
> Not necessarily, this could be used anywhere a mixin can be.
>>> [...]
>> The syntax may conflict with '#line'.
> 
> I didn't know. The choice for the symbol is not that important however.
> 
>> What to do where there are multiple attributes? E.g.
>> 
>> #license!"BSD" @safe #memoize pure nothrow auto invertMatrix(T)(T[]
>> elements) if (isArithmetic!T) { ... }
> 
> Evaluation order stays the same as in this example, the improvement is purely syntactical:
> //
> import std.stdio, std.array;
> 
> string m1( string s ) { return replace( s, "foo", "bar" ); }
> string m2( string s ) { return replace( s, "bar", "baz" ); }
> 
> mixin( m1( q{ mixin( m2( q{ void foo( int i ) {
>     writeln( i );
> }}));}));
> 
> void main() {
>     baz( 42 );
> }
> //
>> What to do with .di files?
>> 
>> // in .di
>> #handler void onLoad();
>> // in .d
>> #handler void onLoad() { .... }
> 
> Since the function receives a string, it can deal with declarations
> differently from definitions, it's only a matter of parser.
>> Besides, what's wrong with using '@'?
>> 
>> @serialize int a;
> Builtin annotations' names are not reserved keywords, so this would be
> possible and ambiguous:
> 
> string safe( string s );
> @safe void foo(); // what @safe stands for?

They could be contextual keywords, just like the 'exit' in scope(exit).
Your # has the same problem. 

So we have

AttributeIdentifier:
    any Identifier except 'safe', 'system', 'trusted', 'disable' and
'property'. 

(Alternatively, implement these 5 things using the CTFE method. )


More information about the Digitalmars-d mailing list