module Cond {
// COND BASICS
import { /Std/Math; }
fn test() {
// cond is a more succinct version of a cascading if/else
// • each condition is evaluated in order until one matches
// • cond is an expression whose value is the matching case
// • the type of the expression is the union of all the case types
// • use _ as the expression to match "all"
let x = rand(); // value between 0..1
let y = cond { // type of y is string
x > 0.6 => "high";
x < 0.3 => "low";
_ => "med";
}
// if the final expression is not _, then cond will
// produce an optional value
let z = cond { // type of z is string? (optional string)
x < 0.1 => "very low";
x < 0.2 => "pretty low";
// if there are no matches, then the results is none
}
}
}