fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 302: String interpolation
Idiom # 302: String interpolation
See
programming-idioms.org
:
Code
s := "Our sun has $x planets"
What are effects?
Runnable Examples
Single variable
ex302 is x := 8 s := "Our sun has $x planets" say s
What are effects?
More complex expressions
ex302a is say "A kibibyte consists of {2**10} bytes, which corresponds to {2**10 * 8} bits."
What are effects?
Both also work for multi line strings
ex302b is # Installing custom handler for the time.now effect # this produces deterministic output, which is also good for testing purpose (time.now ()-> time.date_time 2024 179 11 46 5 0).instate_self ()-> now := time.now.get h := now.hour m0 := now.minute s0 := now.second m := if m0 < 10 then "0$m0" else $m0 s := if s0 < 10 then "0$s0" else $s0 say """ Hello World! This example was written on \ the {(now.day_of_month.as_string + "." + now.month.as_string + "." + now.year.as_string)} The local time was \ $h:$m:$s (CEST)\ """
What are effects?
last changed: 2024-07-01
next: NYI: Idiom # 303: Array with non-default lower bound