jacopy.Expr¶
- class jacopy.Expr¶
Bases:
ABCAbstract base class for all expressions.
Subclasses are immutable. Structural equality and hashing are derived from the node’s type together with a canonical
_key()payload provided by each subclass.- __init__()¶
Methods
__init__()clone()Return
self.find(predicate)Yield descendants (including self) satisfying
predicate.replace_at(path, new)Return a new tree with
newspliced atpath.substitute_atom(dummy, target)Return
selfwith every occurrence ofdummyreplaced bytarget.walk()Pre-order traversal yielding
selffollowed by descendants throughchildrenonly.Attributes
Tuple of immediate children.
is_atom- walk()¶
Pre-order traversal yielding
selffollowed by descendants throughchildrenonly.jacopy.core.traverse.iter_nodes()also descends into therewritable_slotsof operator atoms.
- find(predicate)¶
Yield descendants (including self) satisfying
predicate.
- replace_at(path, new)¶
Return a new tree with
newspliced atpath.pathis a tuple of child indices,(1, 0)means “the first child of the second child”. An empty path replaces the root. Rebuilding uses the raw constructor (no smart-ctor flattening), so the surrounding shape is preserved exactly.
- clone()¶
Return
self.Exprinstances are immutable, so structural sharing is always safe.clone()exists for API symmetry with mutable tree libraries; it does not copy.- Return type:
- substitute_atom(dummy, target)¶
Return
selfwith every occurrence ofdummyreplaced bytarget.dummymust be anAtom. The default implementation does the obvious top-level match, then recurses throughchildren(). Atoms that hide a sub-atom inside a private slot (e.g. a frame vector field carrying aFrameIndex) override this method to expose that hidden state for substitution. Binders that introduce their own dummy (notablyIndexedSum) override to respect shadowing.