Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@mettascript/hyperon

A TypeScript class API for MeTTa atoms, spaces and a runner, modeled on Hyperon's hyperon.atoms and hyperon.base. Where the Python package wraps a Rust core over FFI, this one wraps the immutable terms of @mettascript/core in classes, so it runs anywhere TypeScript runs with no native addon and no WASM.

Hyperon's Python method names are kept as aliases beside the idiomatic TypeScript ones, so code ported from hyperon reads naturally: get_name() sits beside name(), get_children() beside children(), add_atom() beside addAtom().

Install

npm install @mettascript/hyperon

In one example

import { MeTTa, S, V, E } from "@mettascript/hyperon";

const metta = new MeTTa();

// The runner's space is live: what you add stays for the next call.
metta.run("(= (fact $n) (if (> $n 0) (* $n (fact (- $n 1))) 1))");
console.log(metta.run("!(fact 5)")[0]!.map(String)); // [ '120' ]

// Or work in atoms instead of text. S is a symbol, V a variable, E an expression.
metta.space().addAtom(E(S("parent"), S("Tom"), S("Bob")));
const set = metta.space().query(E(S("parent"), S("Tom"), V("c")));
console.log(set.frames.map((f) => f.resolve(V("c"))!.toString())); // [ 'Bob' ]

A query answers with binding frames rather than atoms, because a query asks what the variables could be. resolve reads one variable out of a frame.

Where the documentation lives

The guide on the website teaches this package properly:

If you would rather not write atoms by hand, @mettascript/edsl builds them for you and types the results.

For language models

LLMS.md is a one-page, high-density reference for this package: API surface, working examples, and the mistakes that produce wrong code. The repository root carries an llms.txt index of all of them.

License

MIT.