:>> [[ABIO]] → ABIO Docs → Modules ABIO expr API Reference
Expr Module¶
The Expr language: forms, the environment, the registry, the interpreter, the YAML tags, includes. The user-facing specification is ABIO Expr Spec; the Python side is ABIO Expr Python API.
alienbio.expr
¶
alienbio.expr — the Expr language (M47): forms, the interpreter, the
head registry, the three spellings. See the vault's ABIO Expr Spec and
ABIO Expr Python API.
from alienbio.expr import X, Env, evaluate, fn, expander
env = Env.standard(seed=7)
evaluate(X.lognormal(1.0, 0.3), env) # a draw
evaluate(X.parse("max(2, poisson(3))"), env) # the inline spelling
Ctx
dataclass
¶
The per-node context: seed, path (for messages), trust, limits.
Source code in src/alienbio/expr/env.py
Env
¶
Bindings + heads + context. Immutable in spirit: every child /
bind / with_* returns a new Env sharing what is unchanged.
Source code in src/alienbio/expr/env.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
standard(seed=0, *, trusted=False, registry=None, limits=None, bindings=None)
classmethod
¶
An environment over the default registry with root seed seed.
Source code in src/alienbio/expr/env.py
child(label)
¶
The env for a named sub-node: same scope, child seed, extended path.
bind(**values)
¶
scope(data=None, parent=None)
¶
A child scope over parent (default: this env's bindings).
Source code in src/alienbio/expr/env.py
lookup(path)
¶
Resolve a dotted name: first segment in the scope chain, then steps.
Source code in src/alienbio/expr/env.py
head(name)
¶
A head by name: a locally bound head (a YAML template) shadows the registry.
Source code in src/alienbio/expr/env.py
load(source, *, text=None, base=None)
¶
Load a YAML document into a child scope: every top-level key becomes
a (lazy) binding. Includes and !py references are resolved first
(:mod:alienbio.expr.include) relative to base — the file's own
directory by default — under this env's trust. Returns the env whose
scope holds the bindings.
Source code in src/alienbio/expr/env.py
hydrate(data, *, base=None)
¶
Resolve includes / !py references inside already-loaded forms.
Source code in src/alienbio/expr/env.py
pool(name)
¶
A pool name as seen from this scope (M47.5): inside a template
instance a name is namespaced by the instance (krel.ME1) unless it
arrived as an argument, in which case it is whatever the caller's
scope called it — that is how a parent wires its children. Outside any
template the name is itself.
Source code in src/alienbio/expr/env.py
force_all()
¶
Evaluate every lazy binding in this scope (not parents); returns them.
Source code in src/alienbio/expr/env.py
ExprError
¶
Bases: ValueError
Every Expr failure, with the path of the node that failed. A
ValueError: a document that fails to evaluate is an invalid value.
Source code in src/alienbio/expr/env.py
Limits
dataclass
¶
Caps the interpreter enforces — exceeding one is an error, never a truncation.
Source code in src/alienbio/expr/env.py
charge(n, path, what)
¶
Count n elements against the session total; raise past the cap.
Source code in src/alienbio/expr/env.py
UnsafeSpecError
¶
Bases: Exception
Raised when an untrusted spec asks for code execution (a .py
include, !py) or a file outside its own directory.
Call
dataclass
¶
head(*args, **kwargs) as data. head names a registered function,
expander, template or special form; the arguments are forms.
Source code in src/alienbio/expr/form.py
Name
dataclass
¶
A lookup: path is ident(.ident)* — the first segment resolves in
the scope chain, each further segment steps into the value (mapping key,
then attribute, then sequence index).
Source code in src/alienbio/expr/form.py
Quoted
dataclass
¶
A form held as a value. Evaluating a Quoted yields a
:class:~alienbio.expr.interp.QuotedForm — the form closed over the
environment it was written in, sampleable as a Dist.
Source code in src/alienbio/expr/form.py
QuotedForm
dataclass
¶
A quoted form as a value: the form plus the environment it was written
in. It is a suite.dist.Dist (sample(seed) evaluates the form
under that seed) and exposes run for evaluation with extra bindings.
Source code in src/alienbio/expr/interp.py
TemplateHead
¶
Bases: Head
A head made by the template special form: positional parameter
names, keyword parameters with default forms, a body, and the defining
environment (closure). Calling it evaluates the body in a child scope of
the definition scope, under the call's seed and namespace.
Source code in src/alienbio/expr/interp.py
GuardViolation
¶
Bases: Exception
Raised by a guard to reject what a call produced. offenders names
the elements (keys of a produced mapping, dotted for depth) that
on_fail: prune may drop; a violation without them cannot be pruned.
Source code in src/alienbio/expr/registry.py
Registry
¶
A name → :class:Head table with kind-filtered views.
Source code in src/alienbio/expr/registry.py
ExprLoader
¶
Bases: SafeLoader
yaml.SafeLoader plus the Expr tags. A subclass, so the global
SafeLoader (and every other loader in the process) is untouched.
contains_form(value)
¶
is_form(value)
¶
True for the three tagged shapes — a literal or data is "a form" too, but only these three carry meaning beyond their Python value.
walk(value)
¶
Pre-order walk over a form tree, yielding every node (data included).
Source code in src/alienbio/expr/form.py
evaluate(form, env)
¶
Evaluate form in env.
Source code in src/alienbio/expr/interp.py
expander(_f=None, *, name=None, guarded=False, guarded_params=(), into=registry, replace=False, **meta)
¶
Register an expander head: fn(args, kwargs, env) receives the
argument forms (unevaluated) and returns a form the interpreter then
evaluates under the call's seed.
Source code in src/alienbio/expr/registry.py
fn(_f=None, *, name=None, kind='fn', guarded=False, guarded_params=(), into=registry, replace=False, **meta)
¶
Register a function head: its arguments arrive evaluated. A
keyword-only ctx / env parameter is injected, never passed by the
spec. kind is the flavor tag (dist, rate, scoring, ...).
Source code in src/alienbio/expr/registry.py
guard(_f=None, *, name=None, into=registry, replace=False, **meta)
¶
Register a guard: fn(value, ctx, **params) returns False or
raises :class:GuardViolation to reject what a call produced. A call's
guards: [...] lists guards by name (defaults) or as calls (parameters);
on_fail: retry | prune | reject decides what a failure does (M47.5).
Source code in src/alienbio/expr/registry.py
dump_structural(form)
¶
Form -> YAML text in the structural spelling (loads back to an equal form).
Source code in src/alienbio/expr/yaml_tags.py
load_text(text)
¶
YAML text -> forms (data with Name / Call / Quoted where tagged).