Developer Preview — APIs and language features may change before 1.0
Expression Standard Library
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
mashinTalk’s expression language ships with built-in namespaces, value methods, and global functions. These are language built-ins compiled directly to BEAM code, not mashinTalk machines. They are available in any expression context: compute steps, decide conditions, field defaults, and string interpolation.
Namespaces
Namespaces are called as Namespace.function(args). Available namespaces:
Merge source into target (source wins on conflict)
Object.assign(target, source)
object, object -> object
Alias for merge
Object.hasKey(obj, key)
object, string -> boolean
True if key exists
Object.get(obj, key)
object, string -> any | nil
Get value or nil if absent
Object.get(obj, key, default)
object, string, any -> any
Get value or default if absent
Object.delete(obj, key)
object, string -> object
Remove a key, return new object
computenormalize
let keys = Object.keys(input.data)
let entries = Object.entries(input.data)
let cleaned = Object.fromEntries(entries.filter(([k, v]) => v !=null))
cleaned
Set
Operations on sets (unordered collections with no duplicates).
Function
Signature
Description
Set.from(list)
array -> Set
Create a set from a list
Set.has(set, value)
Set, any -> boolean
True if value is in the set
Set.add(set, value)
Set, any -> Set
Add a value, return new set
Set.delete(set, value)
Set, any -> Set
Remove a value, return new set
Set.union(a, b)
Set, Set -> Set
All elements in either set
Set.intersection(a, b)
Set, Set -> Set
Elements in both sets
Set.difference(a, b)
Set, Set -> Set
Elements in a but not b
Set.size(set)
Set -> integer
Number of elements
Set.toList(set)
Set -> array
Convert to a list
UUID
Function
Signature
Description
UUID.generate()
-> string
Generate a random UUID v4
UUID.v4()
-> string
Alias for UUID.generate()
Intl
Locale-aware formatting. Uses the machine’s locale when set via written in.
Function
Signature
Description
Intl.formatNumber(num)
number -> string
Format a number for display
Intl.formatNumber(num, opts)
number, object -> string
Format with options: opts.decimals (integer) for decimal places, opts.style: "percent" to multiply by 100 and append %
Intl.formatDate(dt)
string -> string
Format a date/datetime string
Intl.formatDate(dt, opts)
string, object -> string
Format with style: "iso", "date", "time", or "short" (default)
Result
Explicit error handling without exceptions. Use Result to represent operations that may succeed or fail.
Function
Signature
Description
Result.ok(value)
any -> Result
Wrap a success value
Result.error(reason)
any -> Result
Wrap a failure reason
Result.is_ok(r)
Result -> boolean
True if the result is ok
Result.is_error(r)
Result -> boolean
True if the result is an error
Result.map(r, fn)
Result, (any) -> any -> Result
Transform the ok value
Result.and_then(r, fn)
Result, (any) -> Result -> Result
Chain operations that may fail
Result.unwrap_or(r, default)
Result, any -> any
Extract value or use default on error
Result.unwrap!(r)
Result -> any
Extract value, raise if error
Result.try_fn(fn)
(() -> any) -> Result
Wrap a function call, catching errors as Result.error
computesafe_parse
let parsed = Result.try_fn(() => JSON.parse(input.payload))
let data = Result.unwrap_or(parsed, {items: []})
{items: data.items}
Option
Explicit null handling. Use Option to represent values that may or may not be present.
Function
Signature
Description
Option.some(value)
any -> Option
Wrap a present value
Option.none()
-> Option
Represent absence
Option.is_some(o)
Option -> boolean
True if value is present
Option.is_none(o)
Option -> boolean
True if value is absent
Option.map(o, fn)
Option, (any) -> any -> Option
Transform the inner value if present
Option.and_then(o, fn)
Option, (any) -> Option -> Option
Chain operations on optional values
Option.unwrap_or(o, default)
Option, any -> any
Extract value or use default if absent
Option.from_nullable(value)
any | nil -> Option
Convert a nullable value to an Option
String (namespace)
String utility functions callable as String.function(args). See also String value methods for dot-syntax equivalents.
Function
Signature
Description
String.join(list, separator)
array, string -> string
Join a list into a string
String.to_string(value)
any -> string
Coerce any value to a string
String.split(str, delimiter)
string, string -> array<string>
Split a string into a list
String.trim(str)
string -> string
Remove leading and trailing whitespace
String.replace(str, pattern, replacement)
string, string, string -> string
Replace first occurrence
String.length(str)
string -> integer
Character count
String.uppercase(str)
string -> string
Convert to uppercase
String.lowercase(str)
string -> string
Convert to lowercase
form (Governed Metaprogramming)
The form namespace provides access to machine forms: the AST representation of a mashinTalk machine. Use form functions inside compute steps to inspect, transform, and serialize machine structure. form.eval, form.propose, and form.describe require an ask step because they perform governed effects.
Introspection
Function
Signature
Description
form.kind(f)
Form -> string
Node type (e.g. "machine", "step", "section")
form.name(f)
Form -> string
Node name
form.children(f)
Form -> array<Form>
Direct children
form.fields(f)
Form -> object
Field map for the node
form.section(f, name)
Form, string -> Form
Find a section by name
form.step(f, name)
Form, string -> Form
Find a step by name
form.steps(f)
Form -> array<Form>
All steps in the form
form.inputs(f)
Form -> array<Form>
Input field forms
form.outputs(f)
Form -> array<Form>
Output field forms
form.get(f, path)
Form, string -> any
Get a field value by path
Mutation
All mutation functions return a new Form; the original is unchanged.
Function
Signature
Description
form.set(f, path, value)
Form, string, any -> Form
Set a field at path
form.add(f, child)
Form, Form -> Form
Append a child node
form.add(f, position, child)
Form, integer, Form -> Form
Insert a child at position
form.remove(f, name)
Form, string -> Form
Remove a child by name
form.replace(f, name, new_form)
Form, string, Form -> Form
Replace a child by name
form.merge(f1, f2)
Form, Form -> Form
Merge two forms
form.diff(f1, f2)
Form, Form -> object
Diff between two forms
form.insert_before(f, ref, child)
Form, string, Form -> Form
Insert before a named sibling
form.insert_after(f, ref, child)
Form, string, Form -> Form
Insert after a named sibling
form.wrap(f, wrapper_kind)
Form, string -> Form
Wrap a form in a new node of the given kind
form.dissoc(f, key)
Form, string -> Form
Remove a key from fields
form.update(f, key, fn)
Form, string, (any) -> any -> Form
Update a field with a function
form.merge_with(f1, f2, fn)
Form, Form, (any, any) -> any -> Form
Merge forms using a custom conflict resolver
Serialization
Function
Signature
Description
form.to_text(f)
Form -> string
Serialize to mashinTalk source
form.to_text(f, opts)
Form, object -> string
Serialize with options
form.from_text(text)
string -> Form
Parse mashinTalk source into a form
form.to_json(f)
Form -> string
Serialize to JSON
form.from_json(json)
string -> Form
Deserialize from JSON
form.to_minified(f)
Form -> string
Minified mashinTalk source
form.to_node(f)
Form -> object
Convert to a plain object node
Traversal and Search
Function
Signature
Description
form.postwalk(f, fn)
Form, (Form) -> Form -> Form
Walk tree bottom-up, transforming each node
form.prewalk(f, fn)
Form, (Form) -> Form -> Form
Walk tree top-down, transforming each node
form.flatten(f)
Form -> array<Form>
All nodes as a flat list
form.clone(f)
Form -> Form
Deep copy
form.find(f, predicate)
Form, (Form) -> boolean -> Form | nil
First node matching predicate
form.select(f, predicate)
Form, (Form) -> boolean -> array<Form>
All nodes matching predicate
form.some(f, predicate)
Form, (Form) -> boolean -> boolean
True if any node matches
form.every(f, predicate)
Form, (Form) -> boolean -> boolean
True if all nodes match
form.map_children(f, fn)
Form, (Form) -> Form -> Form
Transform direct children only
form.flat_map(f, fn)
Form, (Form) -> array<Form> -> array<Form>
Map then flatten children
Deep Access
Function
Signature
Description
form.get_in(f, path)
Form, array<string> -> any
Get a nested value by path
form.put_in(f, path, value)
Form, array<string>, any -> Form
Set a nested value by path
form.update_in(f, path, fn)
Form, array<string>, (any) -> any -> Form
Update a nested value with a function
Construction
Function
Signature
Description
form.new(kind, name)
string, string -> Form
Create a new form node
form.new(kind, name, fields)
string, string, object -> Form
Create with initial fields
form.from_node(node)
object -> Form
Build a form from a plain object
Analysis
Function
Signature
Description
form.validate(f)
Form -> object
Validate; returns {valid: boolean, errors: array}
form.hash(f)
Form -> string
Content hash of the form
form.capabilities(f)
Form -> array<string>
Capabilities declared or used
form.dependencies(f)
Form -> array<string>
Machine references this form depends on
form.credential_requirements(f)
Form -> array<string>
Credentials required to run
form.explain(f)
Form -> string
Human-readable description
Composition
Function
Signature
Description
form.pipe(f, fns...)
Form, ...(Form) -> Form -> Form
Apply a sequence of transformations
Utilities
Function
Signature
Description
form.frequencies(f)
Form -> object
Map of node kind to count
form.sort_by(f, fn)
Form, (Form) -> any -> array<Form>
Sort children by a key function
form.select_keys(f, keys)
Form, array<string> -> object
Extract named fields as an object
form.group_by(f, fn)
Form, (Form) -> any -> object
Group nodes by a key function
Zipper (cursor-based traversal)
Zippers let you navigate and edit a form tree by keeping a cursor position. Changes made via a zipper are applied when you call form.root.
Function
Signature
Description
form.zipper(f)
Form -> Zipper
Create a zipper at the root
form.down(z)
Zipper -> Zipper
Move to first child
form.up(z)
Zipper -> Zipper
Move to parent
form.left(z)
Zipper -> Zipper
Move to left sibling
form.right(z)
Zipper -> Zipper
Move to right sibling
form.zip_node(z)
Zipper -> Form
Get the form at the current cursor
form.edit(z, fn)
Zipper, (Form) -> Form -> Zipper
Transform the current node
form.zip_replace(z, form)
Zipper, Form -> Zipper
Replace the current node
form.insert_left(z, form)
Zipper, Form -> Zipper
Insert a sibling to the left
form.insert_right(z, form)
Zipper, Form -> Zipper
Insert a sibling to the right
form.zip_remove(z)
Zipper -> Zipper
Remove the current node
form.root(z)
Zipper -> Form
Return the full form with all zipper edits applied
Extensions
Function
Signature
Description
form.generate_inputs(f)
Form -> object
Generate a sample input object matching the form’s accepts contract
form.apply_rules(f, rules)
Form, array -> Form
Apply a list of transformation rules to the form
form.recommend_supervision(f)
Form -> object
Suggest governance settings based on form analysis
Governed effects (require ask step)
These functions perform governed effects and cannot be called in a compute step. Use them inside an ask step.
Function
Description
form.eval(f, input)
Execute the form with a given input object
form.propose(f, name)
Propose the form for promotion under a given name
form.describe(machine_ref)
Load and describe a machine by reference
Value Methods
Value methods are called on a value using dot syntax: value.method(args).