examples
</> Example Implementation
Hello World in MeTTa
A simple introduction to MeTTa syntax showing expression evaluation and pattern matching over a knowledge base.
; Basic MeTTa expression evaluation
!(+ 1 2) ; => 3
; Define a knowledge base
(= (parent Tom Bob))
(= (parent Bob Sam))
; Query relationships
!(match &self (= (parent Tom $x)) $x)
; => Bob
Type-checked functions
Demonstrates MeTTa's dependent type system with a recursive factorial function.
; Define typed functions
(: factorial (-> Number Number))
(= (factorial 0) 1)
(= (factorial $n)
(* $n (factorial (- $n 1))))
!(factorial 5) ; => 120
Atom manipulation
Shows how to dynamically add and query atoms in the Atomspace.
; Add atoms to the space
!(add-atom &self (likes Alice Chess))
!(add-atom &self (likes Bob Music))
; Query all likes
!(match &self (likes $who $what)
($who enjoys $what))