pub enum Value {
Show 15 variants
Nil,
Bool(bool),
Int(i64),
Float(f64),
Str(Arc<str>),
Symbol(Arc<str>),
Keyword(Arc<str>),
List(Arc<Vec<Value>>),
Map(Arc<HashMap<MapKey, Value>>),
Closure(Arc<Closure>),
NativeFn(Arc<NativeFn>),
Promise(Arc<Mutex<PromiseState>>),
Error(Arc<ErrorObj>),
Sexp(Sexp, Span),
Foreign(Arc<dyn Any + Send + Sync>),
}Expand description
An evaluated runtime value.
Variants§
Nil
Bool(bool)
Int(i64)
Float(f64)
Str(Arc<str>)
Symbol(Arc<str>)
Keyword(Arc<str>)
List(Arc<Vec<Value>>)
Map(Arc<HashMap<MapKey, Value>>)
Persistent hash map keyed by a hashable subset of Value
(Bool, Int, Float, Str, Symbol, Keyword, Nil).
Inserting / removing yields a new Map (copy-on-write via Arc).
Closure(Arc<Closure>)
NativeFn(Arc<NativeFn>)
Promise(Arc<Mutex<PromiseState>>)
A delayed (lazy) computation. First force triggers evaluation
of the underlying thunk; subsequent forces return the cached
result. Backed by Mutex so a Promise can be shared across
references safely (single-threaded runtime, but the lock is
trivial overhead and gives us zero-effort safety).
Error(Arc<ErrorObj>)
A first-class structured error — Clojure ex-info shape:
a tag (keyword/string), a message string, and a data plist.
Constructed by (error tag msg data) / (ex-info msg data).
Raised by (throw err). Caught by (try ... (catch (e) ...)).
Sexp(Sexp, Span)
Escape hatch: unevaluated source form carried as a value, e.g. after
(quote x). Preserves span info.
Foreign(Arc<dyn Any + Send + Sync>)
Opaque host-owned value. The embedder supplies these via FFI; native functions read them back via downcast. Used to expose typed Rust handles (job refs, client handles) to Lisp code.
Implementations§
Source§impl Value
impl Value
pub fn symbol(s: impl Into<Arc<str>>) -> Value
pub fn keyword(s: impl Into<Arc<str>>) -> Value
pub fn string(s: impl Into<Arc<str>>) -> Value
pub fn list<I>(xs: I) -> Valuewhere
I: IntoIterator<Item = Value>,
pub fn is_truthy(&self) -> bool
Sourcepub fn is_unique(&self) -> bool
pub fn is_unique(&self) -> bool
Is this Value the only reference to its heap payload?
The aliasing coordinate. true means no other Value anywhere can
observe the payload, so mutating it in place is unobservable and a
copy-on-write copy would be pure waste. false means somebody else
holds it and the copy is mandatory.
Two things it is not:
- Not a static promise. It is a refcount reading at one instant,
which is why it is sound to act on: a primitive that reads
trueholds the value by value, so nothing can acquire a second reference behind its back. - Not observable from the language. No Lisp-visible behaviour depends on it — the same call returns the same value either way. It only decides whether an allocation happens.
Variants with no heap payload (Nil, Bool, Int, Float) are
trivially unique: there is nothing to share. Sexp answers false
because it carries its tree by value and this query cannot see the
sharing inside that tree — and a wrong true is the one answer that
could license an update somebody else observes, so an unmeasured
payload rounds down, never up.