01. Atoms and expressions
Start with one atom: (likes Ada Music).
The whole form is an expression. Its three children are symbols, in order: likes, Ada, and Music. Parentheses give the atom structure. They do not make it run. You can store the expression as data, place it inside another expression, or later evaluate it as a call.
MeTTa exposes the same structure as Python values. S.Ada makes the symbol Ada, V.x makes the variable $x, and applying S.Parent builds an expression. Parsed MeTTa and a Python-built atom are equal:
def test_parse_keeps_variable_names():
p = parse("(Parent $x Bob)")
assert p == S.Parent(V.x, S.Bob)Atoms come in four kinds:
- A symbol is a name such as
Adaorlikes. - A variable is a named position such as
$whothat matching can bind. - A grounded atom carries a host value such as a Python number or string.
- An expression is an ordered group of atoms.
Write S.likes(V.who, S.Music) in Python and you get (likes $who Music). The variable changes one child, but the whole value is still an expression. Building it does not contact the engine.
The atoms and terms guide covers constructors, parsing, operators, unification, and grounded values. Next, put atoms in a space and match them in 02. Spaces and matching.