Standard Library · expr
class Lit
A literal value in the expression: a string, an integer, a float, a decimal, a boolean, or None.
since 0.1.0-alpha.1linuxwindowswasm
- bases
Node
Overview
Enum members appear as Lit nodes holding their integer value. A decimal literal (10.50m, or a literal that adopts decimal beside a decimal operand, as in x.price > 10) is a Lit holding the exact decimal, with the scale it was written with.
Examples
use expr;
use io::console;
expr::Lit a = expr::Lit(42);
expr::Lit c = expr::Lit(None);
var v = a.v;
match (v) {
int => { console.writeln("int ${v}"); }
else => { console.writeln("other"); }
}
console.writeln(c.v == None);
int 42
true
Constructors
new
new(string | int | float | decimal | bool | None value)Create a literal node.
Parameters
- value
- The literal value.
Examples
use expr;
use io::console;
expr::Lit n = expr::Lit(None);
expr::Lit t = expr::Lit(true);
console.writeln(n.v == None);
console.writeln(t.v == None);
true
false
Fields
v
string | int | float | decimal | bool | None vThe literal value. Copy it into a local and narrow that with match before using it as a specific type (a field does not narrow).
See also
- Node — The base class of every node in the reification tree.