Slide 10 of 74

Strings

Interpolation and escapes
proc main(): void {
	name := "bee"
	echo "hello, {name}!"            // interpolated
	echo "{name + name}!"           // any expression
	echo "a literal brace: \{"      // escaped
	echo "tab:\t| quote:\" | \q"    // \q is just q
	echo "two
lines"
}
Backtick strings
proc main(): void {
	name := "bee"
	block := `
		hello, {name}
		a literal brace: \{
		a backslash stays: C:\hive\bin
	`
	echo block
}

A double-quoted string interpolates {expression} — anything that is an expression, not only a name — and may run over several lines. Its escapes are \n, \t, \r, \", \\, and \{ for a literal brace; a backslash before any other character is just that character, so "\q" is q.

A backtick string is for a block of text. Its indentation is stripped at compile time down to the shortest margin its lines share — a tab and a space each count as one — and a blank first or last line is dropped, so it can be indented along with the code around it. It interpolates {expression} too, and its one escape is \{: every other backslash is a backslash, which makes it the place for a regular expression or a Windows path. It cannot hold a backtick at all; join one in with "`" if you need it.

A Str is a value, like an Int: nothing writes into one, and every operation hands back a new string. It is counted, indexed and sliced by character, which the slide after the bounds checker shows.