Can I convert string to expression somehow?

Godnyx rempas at tutanota.com
Sat Dec 12 09:05:19 UTC 2020


I'm trying to create a cool function that will let us do 
formatting sorter and faster. The function will work like that:

outln("My name is {name} and my age is {age}");

this will be equivalent to:

writeln("My name is ", name, " and my age is ", age);

or:

writefln("My name is %s and my age is %d", name, age);

You can see how much sorter and faster this is and how better it 
looks. This is actually the way Rust does it for anyone that 
happen to know. So I'm trying to find a way to convert the 
strings inside the curly braces so I can print them. In our 
example the function must do

write("My name is ");
write(name);
write("and my age is ");
write(age);

So yeah I want a way to convert the strings into expressions if 
that's possible. I also tried mixins but the variable cannot read 
at compile time so I'm out of luck...


More information about the Digitalmars-d-learn mailing list