-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MeTTa --compile=full examples/baseline_compat/hyperon-mettalog_sanity…
…/fibo_hang.metta runs !(fibo 80) in 2.24 milliseconds
- Loading branch information
Showing
14 changed files
with
603 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
examples/baseline_compat/hyperon-mettalog_sanity/fibo_hang.metta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
(= (fib $n) | ||
(if (== $n 0) | ||
0 | ||
(if (== $n 1) | ||
1 | ||
(+ (fib (- $n 1)) (fib (- $n 2)))))) | ||
|
||
(= (fib1 $a $b $n $i) | ||
(if (< $n 3) | ||
(fib $n) | ||
(if (== $i (- $n 2)) | ||
(+ $a $b) | ||
(fib1 $b (+ $a $b) $n (+ $i 1))))) | ||
|
||
|
||
!(println! (fib 12)) | ||
|
||
!(fib1 0 1 100 0) | ||
|
||
!(println! (fib1 0 1 80 0)) | ||
|
||
!(fib 80) | ||
|
||
|
||
!(println! (fib 20)) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
|
||
% eval_80/6: Evaluates a Python function call within MeTTa. | ||
% Parameters: | ||
% - Eq: denotes get-type, match, or interpret call. | ||
% - RetType: Expected return type of the MeTTa function. | ||
% - Depth: Recursion depth or complexity control. | ||
% - Self: Context or environment for the evaluation. | ||
% - [MyFun|More]: List with MeTTa function and additional arguments. | ||
% - RetVal: Variable to store the result of the Python function call. | ||
eval_80(Eq, RetType, Depth, Self, [MyFun|More], RetVal) :- | ||
% MyFun as a registered Python function with its module and function name. | ||
metta_atom(Self, ['registered-python-function', PyModule, PyFun, MyFun]), | ||
% Tries to fetch the type definition for MyFun, ignoring failures. | ||
(( get_operator_typedef(Self, MyFun, Params, RetType), | ||
try_adjust_arg_types(RetType, Depth, Self, [RetType|Params], [RetVal|More], [MVal|Adjusted]) | ||
)->true; (maplist(as_prolog, More , Adjusted), MVal=RetVal)), | ||
% Constructs a compound term for the Python function call with adjusted arguments. | ||
compound_name_arguments(Call, PyFun, Adjusted), | ||
% Optionally prints a debug tree of the Python call if tracing is enabled. | ||
if_trace(host;python, print_tree(py_call(PyModule:Call, RetVal))), | ||
% Executes the Python function call and captures the result in MVal which propagates to RetVal. | ||
py_call(PyModule:Call, MVal), | ||
% Checks the return value against the expected type and criteria. | ||
check_returnval(Eq, RetType, RetVal). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.