String Formatting

Formatting strings is an incredibly common programming task, whether it be for the sake of debugging or for building full-fledged CLI programs. Claro attempts to simplify this process by providing syntax sugar for directly templating arbitrary expressions directly into a string.

Note: At the moment, Claro only supports single-line strings, but multi-line strings are planned. Stay tuned for this in a future release.

To take advantage of this, any expression can be formatted into a string by wrapping it in {...}.

Fig 1:

var s = "!EXAMPLE!";

provider foo() -> string {
  return "WOW!";

# Formatted expressions really are arbitrary expressions, you can even call
# arbitrary procedures from them.

# Format strings can even be nested, though you should probably have a good
# reason for doing this.

# You can also use multiple fmt arg expressions!
print("Name:\t{getRandomName()}\nAge:\t{random::nextNonNegativeBoundedInt(random::forSeed(1), 20)}");

provider getRandomName() -> string {
  # ...
  var names = ["Milo", "Millie", "Ruby"];

    |> random::nextNonNegativeBoundedInt(^, 3)
    |> var ind = ^;

  return names[ind];


Name:	Millie
Age:	5

Escaping Curly-Braces in Strings

While Format Strings are very convenient, this does have the consequence of giving curly-braces a special significance in string literals. So, to type a string literal that contains the { char, you must escape it using \{, for example:

Fig 2:

print("This string has \{literal \{curlies} in it}");


This string has {literal {curlies} in it}