-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfstring.casa
More file actions
35 lines (33 loc) · 933 Bytes
/
fstring.casa
File metadata and controls
35 lines (33 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# F-string interpolation examples
import "std"
# Basic f-string with a variable
"world" = greeting
f"hello {greeting}\n" print
# Multiple expressions in one f-string
"Alice" = first
"Smith" = last
f"{first} {last}\n" print
# Escaped braces produce literal braces
f"\{braces\}\n" print
# F-string inside a function
fn greet name:str -> str {
f"hi {name}"
}
"Bob" greet print "\n" print
# Nested string concatenation via f-strings
"casa" = lang
"f-strings" = feature
f"{lang} supports {feature}\n" print
# F-string with escape sequences
f"col1\tcol2\n" print
# F-string with no expressions is just a string
f"plain string\n" print
# Arbitrary types that satisfy the Display trait are auto-converted
42 = count
'A' = letter
true = ready
f"count={count} letter={letter} ready={ready}\n" print
# Containers and Option[T] also satisfy Display
[1, 2, 3] (array[int]) = nums
5 Option::Some = maybe
f"nums={nums} maybe={maybe}\n" print