DollarstringsAugust 30. 2010
Dollarstring - embedd expressions in stringsWirbel provides a syntax for embedding variables directly into strings - very much like in shell scripts: name = "Hugo" print($"His name was $name.") The variables do not need to be of type string. They will be converted into strings automatically by making use of the function str: years = 10 print($"And he was $years years old.") You can even embedd expressions by enclosing them into braces:
print($"And that are ${years * 12} months.")
You can use arbitrary expressions as long as they do not contain braces or other strings. Internal representationInternally the Wirbel compiler parses dollar strings into expressions made of strings, + and calls to str. The previous example will produce exactly the same code as:
print("And that are " + str(years * 12) + " months.")
VersionDollar strings first appeared in Wirbel 0.1.10. |
| |||||||||||||||||||||