Amalgams

Internal documentation for the amalgam.amalgams module.

class amalgam.amalgams.Amalgam[source]

The abstract base class for language constructs.

_make_repr(value: Any) → str[source]

Helper method for creating a __repr__().

bind(environment: amalgam.environment.Environment)amalgam.amalgams.Amalgam[source]

Protocol for implementing environment binding for Function.

This base implementation is responsible for allowing bind to be called on other Amalgam subclasses by performing no operation aside from returning self.

call(environment: amalgam.environment.Environment, *arguments: amalgam.amalgams.Amalgam)amalgam.amalgams.Amalgam[source]

Protocol for implementing function calls for Function.

This base implementation is responsible for making the type signature of SExpression.func to properly type check when SExpression.evaluate() is called, as well as raising NotImplementedError for non-callable types.

abstract evaluate(environment: amalgam.environment.Environment) → Any[source]

Protocol for evaluating or unwrapping Amalgam objects.

class amalgam.amalgams.Atom(value: str)[source]

An Amalgam that represents different atoms.

value

The name of the atom.

Type

str

evaluate(_environment: amalgam.environment.Environment)amalgam.amalgams.Atom[source]

Evaluates to the same Atom reference.

class amalgam.amalgams.Numeric(value: N)[source]

An Amalgam that wraps around numeric types.

Parameterized as a Generic by: N = TypeVar("N", int, float, Fraction)

value

The numeric value being wrapped.

Type

N

evaluate(_environment: amalgam.environment.Environment)amalgam.amalgams.Numeric[source]

Evaluates to the same Numeric reference.

class amalgam.amalgams.Symbol(value: str)[source]

An Amalgam that wraps around symbols.

value

The name of the symbol.

Type

str

evaluate(environment: amalgam.environment.Environment)amalgam.amalgams.Amalgam[source]

Searches the provided environment fully with Symbol.value. Returns the Amalgam object bound to the Symbol.value in the environment. Raises environment.SymbolNotFound if a binding is not found.

class amalgam.amalgams.Function(name: str, fn: Callable[[], amalgam.amalgams.Amalgam], defer: bool = False, contextual: bool = False)[source]

An Amalgam that wraps around functions.

name

The name of the function.

Type

str

fn

The function being wrapped. Must have the signature: (env, amalgams…) -> amalgam.

Type

Callable[..., Amalgam]

defer

If set to True, arguments are wrapped in Quoted before being passed to Function.fn.

Type

bool

contextual

If set to True, disallows function calls when Function.in_context is set to False.

Type

bool

env

The environment.Environment instance bound to the function. Overrides the environment parameter passed to the Function.call() method.

Type

environment.Environment

in_context

Predicate that disallows functions to be called outside of specific contexts. Makes Function.call() raise DisallowedContextError when set to False and Function.contextual is set to True.

Type

bool

bind(environment: amalgam.environment.Environment)amalgam.amalgams.Function[source]

Sets the Function.env attribute and returns the same Function reference.

call(environment: amalgam.environment.Environment, *arguments: amalgam.amalgams.Amalgam)amalgam.amalgams.Amalgam[source]

Performs the call to the Function.fn attribute.

Performs pre-processing depending on the values of Function.defer, Function.contextual, and Function.in_context,

evaluate(_environment: amalgam.environment.Environment)amalgam.amalgams.Function[source]

Evaluates to the same Function reference.

with_name(name: str)amalgam.amalgams.Function[source]

Sets the Function.name attribute and returns the same Function reference.

class amalgam.amalgams.SExpression(*vals: amalgam.amalgams.Amalgam)[source]

An Amalgam that wraps around S-Expressions.

vals

Entities contained by the S-Expression.

Type

Tuple[Amalgam, ...]

evaluate(environment: amalgam.environment.Environment)amalgam.amalgams.Amalgam[source]

Evaluates func using environment before invoking the call() method with environment and SExpression.args.

property args

The rest of the SExpression.vals.

property func

The head of the SExpression.vals.

class amalgam.amalgams.Vector(*vals: T)[source]

An Amalgam that wraps around a homogenous vector.

Parameterized as a Generic by: T = TypeVar("T", bound=Amalgam)

vals

Entities contained by the vector

Type

Tuple[T, ...]

mapping

Mapping representing vectors with Atom s for odd indices and Amalgam s for even indices.

Type

Mapping[str, Amalgam]

_as_mapping() → Mapping[str, amalgam.amalgams.Amalgam][source]

Attemps to create a Mapping[str, Amalgam] from Vector.vals.

Odd indices must be Atom s and even indices must be Amalgam s. Returns an empty mapping if this form is not met.

evaluate(environment: amalgam.environment.Environment)amalgam.amalgams.Vector[source]

Creates a new Vector by evaluating every value in Vector.vals.

class amalgam.amalgams.Quoted(value: T)[source]

An Amalgam that defers evaluation of other Amalgam s.

Parameterized as a Generic by: T = TypeVar("T", bound=Amalgam)

value

The Amalgam being deferred.

Type

T

evaluate(_environment: amalgam.environment.Environment)amalgam.amalgams.Quoted[source]

Evaluates to the same Quoted reference.

class amalgam.amalgams.Internal(value: P)[source]

An Amalgam that holds Python object s.

Parameterized as a Generic by: P = TypeVar("P", bound=object)

value

The Python object being wrapped.

Type

P

evaluate(_environment: amalgam.environment.Environment)amalgam.amalgams.Internal[source]

Evaluates to the same Internal reference.

class amalgam.amalgams.DisallowedContextError[source]

Raised on functions outside of their intended contexts.