pub enum Value {
Show 14 variants
Nil,
True,
False,
Number(isize),
Float(f64),
Char(char),
Cons {
car: ArenaIndex,
cdr: ArenaIndex,
},
Symbol {
chars: ArenaIndex,
},
Lambda {
data: ArenaIndex,
},
Builtin(Builtin),
StdLib {
func: StdLib,
cache: ArenaIndex,
},
Array {
data: ArenaIndex,
len: usize,
},
String {
data: ArenaIndex,
len: usize,
},
Native {
id: usize,
name_hash: usize,
},
}Expand description
A Lisp value
Variants§
Nil
The empty list (NOT false - use False for that)
True
Boolean true (#t)
False
Boolean false (#f) - the ONLY false value
Number(isize)
Integer number (exact)
Float(f64)
Floating-point number (inexact)
Char(char)
Single character (used in strings and symbol storage)
Cons
Cons cell (pair)
Symbol
Symbol (contains a contiguous string)
The chars field points to a Value::String which contains the symbol name.
The length is obtained from the String value, providing a single source of truth.
Fields
chars: ArenaIndexLambda
Lambda / closure (memory-optimized)
To minimize enum size, lambda data is stored as a linked list in the arena:
data points to a cons cell (params . (body . env)) where:
params: List of parameter symbolsbody: Expression to evaluateenv: Captured environment (alist)
Use Lisp::lambda() to create and Lisp::lambda_parts() to extract.
Fields
data: ArenaIndexBuiltin(Builtin)
Built-in function (optimized)
StdLib
Standard library function (stored in static memory with caching)
Unlike Lambda which stores code in the arena, StdLib references static function definitions. The function body is parsed on first call and cached, providing good performance while minimizing initial arena cost.
§Memory Efficiency
- Function definitions are in static memory (const strings)
- Parsed body and params are cached on first call
- Subsequent calls reuse the cached parsed AST
§Cache Field
cache: NULL until first call, then points to(body . params)cons cell
Use Lisp::stdlib() to create and Lisp::stdlib_cache() to access cache.
Array
Array (contiguous storage of values in the arena)
Arrays store values contiguously in the arena, similar to how symbols store characters. This provides O(1) indexed access and mutation.
§Memory Layout
datapoints to the first element in contiguous storage- Elements are stored at data+0, data+1, …, data+(len-1)
§Example
(define arr (make-array 3 0)) ; Create array of 3 zeros
(array-set! arr 1 42) ; Set index 1 to 42
(array-ref arr 1) ; => 42
(array-length arr) ; => 3String
String (contiguous storage of Char values in the arena)
Strings store characters contiguously in the arena, similar to arrays. This provides O(1) indexed access and O(1) length lookup.
§Memory Layout
datapoints to the first character in contiguous storage- Characters are stored at data+0, data+1, …, data+(len-1)
§Example
(string-length "hello") ; => 5
(string-ref "hello" 0) ; => #\hNative
Native function (Rust function callable from Lisp)
Native functions are registered at runtime and identified by their ID. The actual function pointer is stored in the evaluator’s NativeRegistry.
§Fields
id: Index into the NativeRegistry’s entries arrayname_hash: Hash of the function name for quick comparison
Implementations§
Source§impl Value
impl Value
Sourcepub const fn is_false(&self) -> bool
pub const fn is_false(&self) -> bool
Check if this value is false (#f) This is the ONLY way to be false in this Lisp
Sourcepub const fn is_boolean(&self) -> bool
pub const fn is_boolean(&self) -> bool
Check if this value is a boolean (#t or #f)
Sourcepub const fn is_integer(&self) -> bool
pub const fn is_integer(&self) -> bool
Check if this value is an integer
Sourcepub const fn is_builtin(&self) -> bool
pub const fn is_builtin(&self) -> bool
Check if this value is a builtin
Sourcepub const fn is_procedure(&self) -> bool
pub const fn is_procedure(&self) -> bool
Check if this value is a procedure (lambda, builtin, stdlib, or native function)