type ml_value_t

Represents a Minilang value. Every Minilang value must contain this struct at the start.

const ml_type_t *Type

Type of this value.

type ml_type_t

Represents a Minilang type.

Although this is not a completely opaque type, avoid creating instances directly and instead use the ML_TYPE macro to declare and initialize a ml_type_t.

const ml_type_t *Type

Type of this value. Will be MLTypeT or a sub type of it.

const ml_type_t **Types

NULL-terminated array of parent types used for method resolution.

const char *Name

A short string name for the type, used for the default string conversion and error messages.

long (*hash)(ml_value_t*, ml_hash_chain_t*)

Function for hashing instances of this type.

void (*call)(ml_state_t*, ml_value_t*, int, ml_value_t**)

Function for calling instances of this type.

ml_value_t *(*deref)(ml_value_t*)

Function for dereferencing instances of this type.

ml_value_t *(*assign)(ml_value_t*, ml_value_t*)

Function for assigning values to instances of this type.

ml_value_t *Constructor

Minilang function to call when calling this type as a constructor.


Declares and initializes a new type.

PARENTS must be a list of parent types written in parentheses (Type₁, Type₂, ...). It is not necessary to include MLAnyT (the base type of all types). The list of parent types can be empty.

The callback functions are initialized to defaults and should be overridden if required using designated initializers: e.g. .deref = my_deref.


Same as ML_TYPE for types with empty instances (and thus behave as an interface).

ml_type_t MLTypeT[]

The type of Minilang types.

ml_type_t MLAnyT[]

The root type of all Minilang values.

ml_value_t MLNil[]

The nil value.

ml_value_t MLSome[]

A non-nil value. Has no other use.

int ml_is(const ml_value_t *Value, const ml_type_t *Type)

Returns 1 if Value is an instance of Type or a subtype, returns 0 otherwise.

long ml_hash_chain(ml_value_t *Value, ml_hash_chain_t *Chain)

Returns a hash value for Value. Uses Chain to break cycles while hashing.

Chain can be NULL for the top-level call to ml_hash_chain(), hash functions for structures which may introduce cycles should create a new ml_hash_chain_t and pass that to their calls to ml_hash_chain().

long ml_hash(ml_value_t *Value)

Equivalent to ml_hash_chain().

type ml_hash_chain_t

If ml_hash_chain() is called with a value already in the chain, the previous index is returned, preventing cycles.

ml_hash_chain_t *Previous

Previous link in the hash chain.

ml_value_t *Value

The value that was encountered.

long Index

The previous index when the value was encountered.

ml_type_t MLSequenceT[]

An interface for all sequence types.

void ml_iterate(ml_state_t *Caller, ml_value_t *Value)

Start iterating over Value. Resumes Caller with an iterator (or nil if Value is empty, or an error if Value is not sequence or another error occurs).

void ml_iter_value(ml_state_t *Caller, ml_value_t *Iter)
void ml_iter_key(ml_state_t *Caller, ml_value_t *Iter)
void ml_iter_next(ml_state_t *Caller, ml_value_t *Iter)