-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Describe the bug
An attempt to "execute" a space as a function actually leads to it being matched against many queries from stdlib.
To Reproduce
from hyperon import *
class MySpace(AbstractSpace):
def __init__(self):
super().__init__()
def query(self, query_atom):
print("query is called:", query_atom)
new_bindings_set = BindingsSet.empty()
return new_bindings_set
def execute(self, *atoms, res_typ=AtomType.UNDEFINED):
print("execute is called", *atoms)
a = G(SpaceRef(MySpace()))
m = MeTTa()
m.evaluate_atom(E(a))Expected behavior
Nothing is executed or "execute is called" is printed.
Actual behavior
query is called: id
query is called: atom-subst
query is called: if-decons-expr
query is called: if-error
query is called: return-on-error
query is called: switch
query is called: switch-internal
query is called: is-function
query is called: type-cast
query is called: match-types
query is called: first-from-pair
query is called: match-type-or
query is called: filter-atom
query is called: map-atom
query is called: foldl-atom
query is called: if
query is called: or
query is called: or
query is called: or
query is called: or
query is called: and
query is called: and
query is called: and
query is called: and
query is called: not
query is called: not
query is called: let
query is called: let*
query is called: add-reduct
query is called: car-atom
query is called: cdr-atom
query is called: quote
query is called: unquote
query is called: nop
query is called: nop
query is called: empty
query is called: unique
query is called: union
query is called: intersection
query is called: subtraction
query is called: add-reducts
query is called: add-atoms
query is called: get-doc
query is called: get-doc-single-atom
query is called: get-doc-function
query is called: undefined-doc-function-type
query is called: get-doc-params
query is called: get-doc-atom
query is called: help!
query is called: help-param!
query is called: for-each-in-atom
query is called: noreduce-eq
query is called: assertEqual
query is called: assertAlphaEqual
query is called: assertEqualToResult
query is called: assertAlphaEqualToResult
query is called: collapse
Additional context
Most likely, the following query is constructed in attempt to execute a space as a function:
(match &self (= (&myspace) $r) $r)
Then, &self is matched against (= (&myspace) $r) $r), and this equality is matched against each equality in &self (and its subspaces such as stdlib). And thus, &myspace receives functional symbols as queries (although it is not precisely clear why non-zero arity functional symbols appear here).
Nothing too bad is happening, since E(a) will not be reduced unless these queries will be matched against something in the space. It might not be considered as a bug, because an attempt to construct an equality query (if this is what really happening) is natural.
However, what can be desirable is execute method to be called instead of query. Unfortunately, this is not the case now. Also, adding execute to SpaceRef doesn't help. It's still query, which got called.
Also, if we try executing m.evaluate_atom(E(a, S('A'))), the "parameter" (S('A')) doesn't get into query (and doesn't influence on the result, so what's happening might be somewhat different from just constructing an equality query). Apparently, this situation can be improved.