Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal MeTTa interpreter fixes and optimizations #429

Merged
merged 27 commits into from
Sep 13, 2023

Conversation

vsbogd
Copy link
Collaborator

@vsbogd vsbogd commented Sep 12, 2023

Next batch of minimal MeTTa related fixes and changes:

  • minimal feature is added to switch core library to the minimal MeTTa interpreter at compile time, one can run Rust unit tests using cargo test --features minimal
  • minimal MeTTa's match is renamed to unify because previous match definition has different order of arguments and thus incompatible with new one, old match is added into minimal MeTTa standard library
  • pattern matcher syntax extensions suggestions are added to the minimal MeTTa docs, docs are fixed
  • assert..., collapse, superpose, let and let*, case, match and pragma! are added into minimal MeTTa standard library, some of them are added as grounded atoms because they require the working atomspace to evaluate arguments which is not implemented yet
  • Void is added as a result of assert... operation, this is to handle Chaining of functions with side effects with guaranteed order #390 in minimal MeTTa
  • NotReducible is returned instead of Empty by minimal MeTTa interpreter when function definition is not found. This corresponds to the previous interpreter's behavior. Two major use-cases are type constructors (which are usually have no definition only type declaration) and partially defined functions (which return results on some arguments and stay non-reducible on others).
  • benchmark for the nested chain operation is added and chain implementation is optimized
  • few small fixes

Better to review commit by commit.

This implementation calls interpret() function inside directly which is
not a minimal MeTTa way. The proper way is to implement it in MeTTa
using pure interpret() and collapse() function. Less proper way is to
return `(interpret $atom %Undefined% <space>)` from grounded Assert...Op
operation. But current implementation is added to quickly migrate to the
minimal MeTTa interpreter.
Add standard atoms collection into C API and use it in Python API to
check the equality with predefined atom.
In case of function call empty result means the function is not defined
on the passed arguments. Thus the whole branch is removed from the plan.
In case of tuple call empty result means there is no function which
matches this tuple. Thus original tuple is returned as a result.
This corresponds to the core functionality implemented in a previous
version of the interpreter. When function definition cannot be found the
atom is returned as is. Two major use-cases are type constructors (which
are usually have no definition only type declaration) and partially
defined functions (which return results on some arguments and stay
non-reducible on others).
Use if-equal to check equality of atoms instead of matching as matching
doesn't work for variable types. Add return type checking step into
interpret-args function.
Now empty vector returned from GroundedAtom means value of the unit type
Void. Thus returning empty collection should be interpreted as Empty.
Remove unnecessary cloning, bindings merge, bindings application. Add
separate branch without cloning for the typical case with single result.
This is to make tests for the old interpreter green again.
@vsbogd vsbogd changed the title Minimal interpreter Minimal MeTTa interpreter fixes and optimizations Sep 12, 2023
@vsbogd
Copy link
Collaborator Author

vsbogd commented Sep 13, 2023

Added minimal feature to the Rust REPL in 5f96b07 in order to use it with minimal MeTTa.

Unfortunately I see the result of execution from old Python repl and new Rust repl are different. For instance the Nil's example:

(: foo (-> Number Number))
(= (foo $x) 123)
(= (Foo) "abc")
!(foo (Foo))

returns [(Error "abc" BadType)] in Python and [123] in Rust. At the same time from the log I see that new minimal interpreter is used in both cases. In Rust REPL's log I see an additional query is made after each eval. May be this difference causes the different result.

@vsbogd
Copy link
Collaborator Author

vsbogd commented Sep 13, 2023

Unfortunately I see the result of execution from old Python repl and new Rust repl are different.

Ok, I have found the root cause: in Python interpreter "abc" is considered as a grounded string with specific type String, in Rust REPL it is considered as a symbol atom with %Undefined% type, thus it can be also casted to Number

Test fails because stdlib is not loaded. In minimal MeTTa case it is
critical because stdlib contains interpreter's implementation.
Copy link
Collaborator

@Necr0x0Der Necr0x0Der left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks convenient to start playing with Minimal MeTTa

@vsbogd
Copy link
Collaborator Author

vsbogd commented Sep 13, 2023

Merging it after confirming with @Necr0x0Der and @luketpeterson

@vsbogd vsbogd merged commit dce575b into trueagi-io:main Sep 13, 2023
1 check passed
@vsbogd vsbogd deleted the minimal-interpreter branch September 13, 2023 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants