Reference
Implementation-agnostic set builders.
This module defines a tiny DSL of lazy "set builders" that describe sets and
set operations without committing to a concrete representation. A SetBuilder
is realized by an Impl[R] (see pyspect.impls.*), which interprets operations
(e.g., empty, complement, intersect, polytope).
Key ideas
- Builders are composable and track requirements on the target
Impl. - Builders can carry named free variables (ReferredSet) resolved at realization.
- AppliedSet defers a call to an
Implmethod by name until realization.
AbsurdSet
Bases: SetBuilder[R]
A builder that cannot be realized.
Used as a sentinel for impossible constructions. Realization raises.
AppliedSet
Bases: SetBuilder[R]
Defer a call to a function f where args can be set builders.
The function is specified by name funcname and looked up on the Impl at
realization, i.e. Impl.<funcname>(*args, **kwds), or a direct lambda if
func is a callable. Only args are allowed to be set builders (or
constants), i.e. kwds are passed directly to the function.
- Accumulates required
Implmethods from children and addsfuncname. - Propagates and de-duplicates children's free variables.
- On realization, calls child builders first, then invokes the
Implmethod. - Wraps child exceptions to pinpoint which argument failed.
ReferredSet
Bases: SetBuilder[R]
Reference a named free variable resolved from the realization mapping.
ReferredSet('X')(impl, X=some_builder) realizes to some_builder(impl, ...).
This is useful in two ways:
1. We can be lazy when constructing the call tree, i.e. we allow users to
define which builder to use at a later stage.
2. This essentially allow variables to exist within the call tree which avoids
having to reconstruct an entire tree in some cases.
Set
SetBuilder
Bases: ImplClient[R]
Abstract base for all set builders.
Responsibilities
- Be callable with an implementation
Impl[R]to produce a concrete setR. - Track required
Imploperations throughImplClient. - Track free variable names (see
ReferredSet).
Subclasses should implement __call__, which is called to realize the sets.
uid
property
Stable hexadecimal id derived from the object hash.
__repr__()
Return a compact identifier for the builder instance.