proposal: a new string litteral to embed variables in a string

Timothee Cour thelastmammoth at gmail.com
Thu Oct 31 15:11:15 PDT 2013


btw, another argument is type safety: my proposal has type safety inherited
from typesafe variadic templates, whereas the "%s" way of doing things is
fragile:

import std.stdio;
void main(){
  writefln("%s%s%s\n",1,2);//crash at RT
  writefln("%s%s\n",1,2,3);//silently accepts even though 1 more argument
  writefln("%s%d\n",1,"foo");//crash at RT: wrong format specifier
}


On Thu, Oct 31, 2013 at 2:37 PM, Jacob Carlborg <doob at me.com> wrote:

> On 2013-10-31 22:24, Timothee Cour wrote:
>
>> the proposed new syntax
>> r{var1=@a; and var2=@foo}
>>
>> is replaced by a tuple:
>> ("var1=", a, "; and var2=", foo)
>> where @ denotes escaping symbols.
>>
>> @ itself be escaped with \@.
>>
>> optionally, expressions can be incorporated:
>> r{a2=@(a*2); and fooU=@(foo.toUpper)}
>>
>
> Would @ be the best symbol for this. It might get confusing with UDA's.
>
> --
> /Jacob Carlborg
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20131031/8933940d/attachment.html>


More information about the Digitalmars-d mailing list