String mixin syntax sugar

dennis luehring dl.soluz at gmx.net
Wed Mar 21 05:52:55 PDT 2012


and what about attribute parameters like @serialize(version=2)

Am 21.03.2012 13:35, schrieb Mantis:
> 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?



More information about the Digitalmars-d mailing list