Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/tabling_fib.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
!(import! &self (library lib_tabling))

!(tabled (fib $N))
(= (fib $N)
(if (< $N 2)
$N
(+ (fib (- $N 1))
(fib (- $N 2)))))

!(test (fib 30) 832040)
11 changes: 11 additions & 0 deletions lib/lib_tabling.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(= (injectPrologCode $code)
(progn (translatePredicate (open_string $code $S))
(translatePredicate (load_files user ((Predicate (stream $S)))))
True))

(: tabled (-> Expression Atom))
(= (tabled $call)
(progn (translatePredicate (atom_string (car-atom $call) $strname))
(translatePredicate (atom_string (+ 1 (length (cdr-atom $call))) $strarity))
(translatePredicate (atomics_to_string (":- table " $strname "/" $strarity ".") $code))
(injectPrologCode $code)))
Loading