method

fun method::list(): list[method]

TBD

fun method::isolate(Args: any, ..., Fn: function): any

Evaluates Fn(Args) in a new method context and returns the result.

fun mlmethodisolated(Arg₁: any)

TBD

type method < function

A map of type signatures to functions. Each type signature consists of a number of types and a flag denoting whether the signature is variadic.

(M: method)(Arg₁, ..., Argₙ)

Calls Fn(Arg₁, ..., Argₙ) where Fn is the function associated with the closest matching type signature defined in M.

A type signature (Type₁, ..., Type/k, Variadic) matches if type(Argᵢ) < Typeᵢ for each \(i = 1, ..., k\) and either \(n = k\) or \(n < k\) and \(Variadic\) is true.

  • A type signature is considered a closer match if its types are closer in terms of subtyping to the types of the arguments.

  • A type signature with the same number of types as arguments is considered a closer match than a matching variadic signature with fewer types.

meth method(): method

Returns a new anonymous method.

meth method(Name: string): method

Returns the method with name Name.

meth (Arg₁: method)[...]

TBD

meth (Arg₁: method):cached

TBD

meth (Arg₁: method):list

TBD

meth method::default(Method: method, ...): error

The default handler for method calls with no matching signature. Returns an error describing the missing signature.

This method can be overridden to create remote proxies, custom error method errors, etc.

"A" *** "B"
:> error("MethodError", "no method found for ***(string, string)")
2 *** "B"
:> error("MethodError", "no method found for ***(integer32, string)")
meth method::default(M: method, X: number, [Y]) 'New default handler! ({M}, {X}, {Y})'
:> @:1
"A" *** "B"
:> error("MethodError", "no method found for ***(string, string)")
2 *** "B" :> "New default handler! (:***, 2, [B])"
meth method::define(Method: method, Types: type, ..., ..?: any, Function: function): Function

Adds a new type signature and associated function to Method. If the last argument is .. then the signature is variadic. Method definitions using meth are translated into calls to method::set.

meth (Method: method):name: string

Returns the name of Method.

meth (Arg₁: string::buffer):append(Arg₂: method)

TBD

meth (Arg₁: string::buffer):append(Arg₂: method::anon)

TBD

type method::context

A context for isolating method definitions.

(C: method::context)(Args: any, ..., Fn: function): any

Calls Fn(Args) in a new context using C for method definitions.

fun method::context(): method::context

Returns a new context for method definitions. The new context will inherit methods definitions from the current context.

type method::isolated < function

TBD