Translator, compiler or interpreter? - trueagi-io/PeTTa GitHub Wiki
Depends, act as compiler:
;Compile function on file load:
(= (f) 42)
;Compile function on file load:
!(add-atom &self (= (f) 42))
;Compile function when compilemyfunc gets called:
(= (compilemyfunc)
(add-atom &self (= (f) 42)))
Act as interpreter:
;MeTTa code to Prolog goals, executing them directly (no clause assertion w. bytecode compilation)
(: myinterpreter (-> Expression %Undefined%))
(= (myinterpreter $code)
(let $temp (println! ("Runtime-interpreting code" $code))
(eval $code)))
!(myinterpreter (if (== 1 1) 42 43))
!(myinterpreter (if (== 1 2) 42 43))
Same translation pipeline ( https://github.com/patham9/PeTTa/blob/main/src/translator.pl ) translating from MeTTa to Prolog, but eval calls the resulting Prolog goals directly (technically compilation to Prolog still, there is no classical AST-walking eval loop of a traditional interpreter) while add-atom of a function asserts the translated clause which triggers clause indexing and compilation to bytecode.