Expand description
§Arena Terms
A lightweight, arena-backed representation of Prolog–like terms.
This crate provides a compact Term type for representing Prolog-like
data structures, along with a typed arena Arena used to
intern atoms, variables, strings, binaries and compound terms. The
underlying representation is designed around a fixed‐width 16
byte handle which carries both the tag and value of a term.
The primary entry points are Arena (for allocating
interned data) and Term (the user visible term handle). Terms
can be matched using the Term::view method which yields a
View that borrows from the underlying arena. Equality and
ordering are well defined according to Prolog’s standard order of
terms. Users may construct lists and tuples conveniently via
macros exported from this crate.
§Example
// create an arena
let mut arena = Arena::new();
// build some primitive terms
let a = arena.atom("hello");
let b = arena.real(3.14);
let c = arena.date(1_640_995_200_000i64); // 2022-01-01T00:00:00Z
// build a long list from an iterator
let xs = arena.list((0..1_000_000).map(|x| x as f64));
// build a compound term using the func! macro
let term = func![
"example";
123, // IntoTerm: integer
"abc", // IntoTerm: &str
list![a, b, c, xs], // nested list (xs is shared)
tuple!(b, a, xs), // nested tuple (xs is shared)
var!("X"), // variable (implicit arena)
=> &mut arena
];
// inspect the resulting term
if let Ok(View::Func(ar, functor, args)) = term.view(&arena) {
assert_eq!(functor.name(ar).unwrap(), "example");
assert_eq!(args.len(), 5);
// view nested terms recursively
match args[2].view(ar).unwrap() {
View::List(_, elems, _) => assert_eq!(elems.len(), 4),
_ => unreachable!(),
}
}§License
Copyright (c) 2005–2025 IKH Software, Inc.
Released under the terms of the GNU Lesser General Public License, version 3.0 or (at your option) any later version (LGPL-3.0-or-later).
Macros§
Structs§
- Arena
- The arena interns atoms, variables, strings, binaries, and compound terms.
AnArenaowns all memory for interned data. Terms store only indices into this arena and remain valid as long as the epoch they belong to is alive. - ArenaID
- Arena
Stats - EpochID
- OperArg
- Represents an additional argument associated with an operator definition.
- OperDef
- Defines a single operator, including its fixity, precedence, associativity, and optional additional parameters.
- Oper
DefTab - Container for operator definitions indexed by
Fixity. - Oper
Defs - Central registry of all operator definitions.
- Term
- A compact, copyable handle referencing a term stored in a
Arena. - Term
Display - A wrapper that ties together a
Termand itsArena, forming the basis for configurable pretty-printing. This type is designed as the foundation on which flexible formatting and printing of terms will be built.
Enums§
- Assoc
- Operator associativity classification.
- Fixity
- Defines the syntactic position (fixity) of an operator.
- Term
Error - Represents all possible errors that can occur within the calculator.
- View
- A borrowed view into the interned contents of a
Term.
Constants§
- MAX_
LIVE_ EPOCHS - MAX_
OPER_ PREC - MIN_
OPER_ PREC - NON_
OPER_ PREC - Default precedence values used for operator definitions.