trueagi-io / hyperon-experimental

MeTTa programming language implementation
https://metta-lang.dev
MIT License
153 stars 50 forks source link

metta function does not use provided space #803

Closed AdrickTench closed 6 days ago

AdrickTench commented 1 week ago

metta does not seem to use the space passed as an argument. The following demonstrates creating a new space and attempting to use it with both match and metta; match uses the space but metta does not.

!(bind! &new-space (new-space)) ;; [()]
!(add-atom &new-space (likes John Jane)) ;; [()]
!(add-atom &new-space (= (foo $x) (+ $x 1))) ;; [()]
!(match &new-space (likes $x $y) ($x $y)) ;; [(John Jane)]
!(metta (foo 1) Number &new-space) ;; [(foo 1)] - why is foo not evaluated here since we passed &new-space?
!(foo 1) ;; [(foo 1)], expected as we're in &self which hasn't defined foo
!(add-atom &self (= (foo $x) (+ $x 1))) ;; [()]
!(foo 1) ;; [2], as expected
!(metta (foo 1) Number &new-space) ;; [2] - now we evaluate foo?
vsbogd commented 1 week ago

Thanks for reporting this. Yes, it is an issue caused by incompatibility of the legacy approach which is evaluation of the MeTTa expressions doesn't input the evaluation context and new approach when context is passed. Looks like in this case it is relatively easy fixable.

vsbogd commented 1 week ago

@AdrickTench could you please check if #804 fixes the issue for you

AdrickTench commented 6 days ago

Confirmed:

> !(bind! &new-space (new-space))
[()]
> !(add-atom &new-space (= (foo $x) (+ $x 1)))
[()]
> !(metta (foo 1) Number &new-space)
[2]