Literals and Escapes
Every string in Zolo uses double quotes. There is no single-quote string
syntax — 'a' is a character literal (type char), useful in comparisons
but distinct from str.
The basic escape sequences are \n (newline), \t (tab),
\" (quote inside a string), and \\ (literal backslash):
Literals, escapes, and the .len() method on simple strings.
01-literals-and-escapes.zolo
// Feature: Strings — literals and escape sequences
// Syntax: `"..."` (the only string form in Zolo)
// When to use: represent text. Single quotes are CHAR literals.
// Strings always use double quotes.
let greeting = "Hello, world!"
print(greeting)
// expected: Hello, world!
// Basic escape sequences.
print("line 1\nline 2") // \n line break
print("col1\tcol2\tcol3") // \t tab
print("quote: \"") // \" literal quote inside string
print("slash: \\") // \\ literal backslash
print("return: end\rstart") // \r carriage return
// Single quotes are CHAR literals (1 character only).
// Useful for character comparisons, not strings.
let c = "a"
print(c == "a")
// expected: true
// Non-ASCII characters / emoji: paste the character directly.
// The `\u{...}` escape is NOT supported by the current lexer.
print("Acai - cafe")
print("emoji: rocket")
// Empty strings and single-char strings.
let empty = ""
let s = "x"
print(empty.len()) // 0
print(s.len()) // 1
Challenge
Create a string containing a backslash followed by a literal n (i.e. the
two characters \ and n, not a newline). Print it and confirm the output
shows \n and not a blank line.
See also