hydra.lisp.coder module
Lisp code generator: converts Hydra type and term modules to Lisp AST.
- hydra.lisp.coder.dialect_cadr(d: Dialect) str
Dialect-aware name for “cadr” (second element of a list); Clojure uses “second”, other dialects use “cadr”.
- hydra.lisp.coder.dialect_car(d: Dialect) str
Dialect-aware name for “car” (first element of a list); Clojure uses “first”, other dialects use “car”.
- hydra.lisp.coder.dialect_constructor_prefix(d: Dialect) str
Dialect-aware constructor prefix for record types; Clojure uses “->”, other dialects use “make-“.
- hydra.lisp.coder.dialect_equal(d: Dialect) str
Dialect-aware name for “equal?” (equality test): Clojure uses “=”, Common Lisp/Emacs Lisp use “equal”, Scheme uses “equal?”.
- hydra.lisp.coder.dialect_supports_letrec(d: Dialect) bool
Whether a dialect provides a native letrec (mutually recursive let); Clojure has only sequential let.
- hydra.lisp.coder.encode_application(dialect: Dialect, overlay_subs: Set[str], cx: T0, g: Graph, raw_fun: Term, raw_arg: Term) object
Encode a function application, detecting ifElse and other lazy primitives; transforms (((hydra.overlay.python.lib.logic.ifElse C) T) E) into native (if C T E).
- hydra.lisp.coder.encode_field_def(ft: FieldType) FieldDefinition
Encode a Hydra field type as a Lisp field definition.
- hydra.lisp.coder.encode_lambda_term(dialect: Dialect, overlay_subs: Set[str], cx: T0, g: Graph, lam: Lambda) object
Encode a Hydra lambda as a Lisp expression.
- hydra.lisp.coder.encode_let_as_lambda_app(dialect: Dialect, overlay_subs: Set[str], cx: T0, g: Graph, bindings: Sequence[Binding], body: Term) object
Encode let bindings as nested ((lambda (x) body) init) applications, for self-referential non-lambda bindings.
- hydra.lisp.coder.encode_let_as_native(dialect: Dialect, overlay_subs: Set[str], cx: T0, g: Graph, bindings: Sequence[Binding], body: Term) object
Encode let bindings as native let, let*, or letrec expressions depending on self-reference and binding count.
- hydra.lisp.coder.encode_literal(lit: Literal) Expression
Encode a Hydra literal as a Lisp expression.
- hydra.lisp.coder.encode_projection_elim(dialect: Dialect, overlay_subs: Set[str], cx: T0, g: Graph, proj: Projection, marg: object) object
Encode a Hydra record projection as a Lisp expression, with an optional argument for applied projections.
- hydra.lisp.coder.encode_term(dialect: Dialect, overlay_subs: Set[str], cx: T0, g: Graph, term: Term) object
Encode a Hydra term as a Lisp expression.
- hydra.lisp.coder.encode_term_definition(dialect: Dialect, overlay_subs: Set[str], cx: T0, g: Graph, tdef: TermDefinition) object
Encode a Hydra term definition as a Lisp top-level form.
- hydra.lisp.coder.encode_type(cx: T0, g: T1, t: Type) object
Encode a Hydra type as a Lisp type specifier, used for type annotations.
- hydra.lisp.coder.encode_type_body(lname: str, orig_typ: Type, typ: Type) object
Encode a type body, after stripping annotations and foralls, as a Lisp top-level form.
- hydra.lisp.coder.encode_type_definition(cx: T0, g: T1, tdef: TypeDefinition) object
Encode a Hydra type definition as a Lisp top-level form.
- hydra.lisp.coder.encode_union_elim(dialect: Dialect, overlay_subs: Set[str], cx: T0, g: Graph, cs: CaseStatement, marg: object) object
Encode a Hydra case statement (union elimination) as a Lisp expression, with an optional argument for applied case statements.
- hydra.lisp.coder.encode_unwrap_elim(dialect: Dialect, overlay_subs: Set[str], cx: T0, g: Graph, name: Name, marg: object) object
Encode a Hydra wrap elimination (unwrap) as a Lisp expression, with an optional argument for applied unwraps.
- hydra.lisp.coder.is_primitive_ref(prim_name: str, term: Term) bool
Check whether a term is a reference to a specific primitive, stripping type applications, type lambdas, and annotations.
- hydra.lisp.coder.lazy_flags_for_primitive_term(g: Graph, head_term: Term) Sequence[bool]
The per-parameter isLazy flags of the primitive a head term refers to, in order; empty if the head is not a registered primitive.
- hydra.lisp.coder.lisp_app(fun: Expression, args: Sequence[Expression]) Expression
A Lisp function application expression.
- hydra.lisp.coder.lisp_keyword(name: str) Expression
Construct a Lisp keyword expression from a string.
- hydra.lisp.coder.lisp_lambda_expr(params: Sequence[str], body: Expression) Expression
An unnamed Lisp lambda expression.
- hydra.lisp.coder.lisp_list_expr(elements: Sequence[Expression]) Expression
Construct a Lisp list expression.
- hydra.lisp.coder.lisp_lit_expr(lit: Literal) Expression
Wrap a Lisp literal as an expression.
- hydra.lisp.coder.lisp_named_lambda_expr(name: str, params: Sequence[str], body: Expression) Expression
A named Lisp lambda expression, for Clojure self-referential fn forms.
- hydra.lisp.coder.lisp_top_form(form: TopLevelForm) TopLevelFormWithComments
Wrap a Lisp top-level form with no doc comment.
- hydra.lisp.coder.lisp_top_form_with_comments(mdoc: object, form: TopLevelForm) TopLevelFormWithComments
Wrap a Lisp top-level form with an optional docstring.
- hydra.lisp.coder.lisp_var(name: str) Expression
A Lisp variable-reference expression (Lisp-1 style, no separate function namespace).
- hydra.lisp.coder.module_exports(forms: Sequence[TopLevelFormWithComments]) Sequence[ExportDeclaration]
Generate export declarations for all symbols defined in a module.
- hydra.lisp.coder.module_imports(dialect: Dialect, overlay_subs: Set[str], focus_ns: ModuleName, defs: Sequence[Definition]) Sequence[ImportDeclaration]
Generate import declarations from the dependency namespaces of a module’s definitions.
- hydra.lisp.coder.module_to_lisp(dialect: Dialect, overlay_subs: Set[str], mod: Module, defs0: Sequence[Definition], cx: T0, g: Graph) object
Convert a Hydra module to a Lisp program.
- hydra.lisp.coder.prim_head_name(term: Term) object
Extract the primitive or variable name a head term refers to, or nothing if the head is not a plain reference.
- hydra.lisp.coder.prim_is_lazy_at(g: Graph, head_term: Term, i: int) bool
Whether the primitive referenced by a head term is lazy in the parameter at the given zero-based position.
- hydra.lisp.coder.qualified_snake_name(name: Name) str
Convert a fully-qualified Hydra Name to a snake_case identifier string.
- hydra.lisp.coder.qualified_type_name(name: Name) str
Convert a fully-qualified Hydra Name to a PascalCase type identifier string.
- hydra.lisp.coder.wrap_in_thunk(expr: Expression) Expression
Wrap an expression in a zero-argument lambda for lazy evaluation.