pub enum Value {
Number(f64),
String(String),
Bool(bool),
Nil,
List(Vec<Value>),
Record {
type_name: Option<String>,
fields: BTreeMap<String, Value>,
},
Color {
r: f64,
g: f64,
b: f64,
a: f64,
},
Result(Box<ResultValue>),
SumVariant {
type_name: String,
variant: String,
fields: Vec<Value>,
},
Function(StdlibFn),
}Expand description
Runtime value in PEPL.
All PEPL values are immutable — operations that “modify” a value return a
new value instead. BTreeMap is used for records to guarantee
deterministic iteration order (a core PEPL invariant).
§Type names
Value::type_name returns the string used by core.type_of():
"number", "string", "bool", "nil", "list", "record" (or the
declared type name for named records/sum variants), "color", "result".
Variants§
Number(f64)
64-bit IEEE 754 floating-point number.
NaN is prevented from entering state — operations that would produce NaN trap instead.
String(String)
UTF-8 string.
Bool(bool)
Boolean value.
Nil
The absence of a value.
List(Vec<Value>)
Ordered collection of values.
Record
Named fields with values. Uses BTreeMap for deterministic ordering.
type_name is Some("Todo") for named record types (type Todo = { ... }),
None for anonymous inline records ({ x: 1, y: 2 }).
Color
RGBA color value. Each component is in the range 0.0–1.0.
Result(Box<ResultValue>)
Result type for fallible operations (Ok or Err).
SumVariant
Sum type variant (e.g., Shape.Circle(5, 10)).
type_name is the declaring sum type (e.g., "Shape").
variant is the variant name (e.g., "Circle").
fields holds positional values — empty for unit variants like Active.
Function(StdlibFn)
A callable function value for higher-order stdlib operations (map, filter, etc.).
Wraps an Arc<dyn Fn> so it can be cloned and passed through Vec<Value>.
The evaluator creates these by wrapping PEPL lambdas/functions.
Implementations§
Source§impl Value
impl Value
Sourcepub fn is_truthy(&self) -> bool
pub fn is_truthy(&self) -> bool
Returns true if this value is truthy.
Truthiness rules (per convert.to_bool):
false,nil,0,""→ falsy- everything else → truthy
Sourcepub fn record(fields: BTreeMap<String, Value>) -> Value
pub fn record(fields: BTreeMap<String, Value>) -> Value
Create an anonymous record (no type name).
Sourcepub fn named_record(
type_name: impl Into<String>,
fields: BTreeMap<String, Value>,
) -> Value
pub fn named_record( type_name: impl Into<String>, fields: BTreeMap<String, Value>, ) -> Value
Create a named record (e.g., type Todo = { ... }).
Sourcepub fn unit_variant(
type_name: impl Into<String>,
variant: impl Into<String>,
) -> Value
pub fn unit_variant( type_name: impl Into<String>, variant: impl Into<String>, ) -> Value
Create a unit sum variant (no payload fields).
Sourcepub fn sum_variant(
type_name: impl Into<String>,
variant: impl Into<String>,
fields: Vec<Value>,
) -> Value
pub fn sum_variant( type_name: impl Into<String>, variant: impl Into<String>, fields: Vec<Value>, ) -> Value
Create a sum variant with positional fields.
Sourcepub fn as_number(&self) -> Option<f64>
pub fn as_number(&self) -> Option<f64>
Try to extract a number, returning None if not a Number.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Try to extract a string reference, returning None if not a String.
Sourcepub fn as_list(&self) -> Option<&[Value]>
pub fn as_list(&self) -> Option<&[Value]>
Try to extract a list reference, returning None if not a List.
Sourcepub fn as_record(&self) -> Option<&BTreeMap<String, Value>>
pub fn as_record(&self) -> Option<&BTreeMap<String, Value>>
Try to extract a record reference, returning None if not a Record.
Sourcepub fn as_variant(&self) -> Option<(&str, &str, &[Value])>
pub fn as_variant(&self) -> Option<(&str, &str, &[Value])>
Try to extract sum variant info: (type_name, variant, fields).
Sourcepub fn as_function(&self) -> Option<&StdlibFn>
pub fn as_function(&self) -> Option<&StdlibFn>
Try to extract a function reference, returning None if not a Function.
Sourcepub fn declared_type_name(&self) -> Option<&str>
pub fn declared_type_name(&self) -> Option<&str>
Returns the declared type name for named records and sum variants.
Returns None for anonymous records and all other value types.