This is how you do string interpolation:
/////////////////////////////////////////
#import <flx.flxh>
var x = "Hello";
var y = "World";
var u = 41;
var z = q"$x $(y) $(1+u) $'2+u'\n";
print z;
/////////////////////////////////////////
prints:
Hello World 42 43
The 'q' character introduces an interpolated string,
any of the usual quoting styles are allowed.
Inside the string, the '$' character introduces
an expression which is evaluated, converted to a string
using the 'str' function, and replaces itself with
that string.
The expression may begin with a '(', in which case
it proceeds up to the balancing ')'. You should note
the scan for brackets ignores other characters,
in particular quote marks, so this form does not
allow you to embed another string containing an
unbalanced bracket.
The expression may begin with a double quote,
single quote, or backtick, in which case it
consists of the text up to the next occurence
of the same kind of quote mark.
Finally, you can just write a Felix identifier,
starting with a letter or underscore, and
continuing with any letter, underscore, digit,
or single quote mark.
NOTE: this feature is implement with vsprintf:
var z = q"$x $(y) $(1+u) $'2+u'\n";
is equivalent to
var z = f"%S %S %S $S\n" (x,y,1+u,2+u);
and is in fact implemented just like that.
Yes this is YASF: Yet Another Silly Feature.
It's designed as another way to do formatting,
similar to Perl (and Tcl).
Ideally it would have been added to C format strings
instead of being a separate kind of string.. however
I couldn't figure out how to do that, since a format
string is actually a function. Roughly, we'd need to
insert the extra arguments into the argument passed
to the function .. but that's tricky since it would
mess up the numbering scheme a bit .. also note
the argument could be a single value or a tuple.
Probably I should do this .. hmm..
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language