trueagi-io / hyperon-experimental

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

MeTTa definitions of stdlib don't work in modules imported by import! function #572

Closed vsbogd closed 9 months ago

vsbogd commented 9 months ago

Code which uses MeTTa definitions of stdlib inside a module imported using import! doesn't work:

Steps to reproduce imported.metta:

!(if True (println! imported-ok) (println! imported-nok))

import.metta:

!(import! &m imported.metta)

!(if True (println! self-ok) (println! self-nok))

Run import.metta

Expected result

metta import.metta
imported-ok
self-ok
[()]
[()]

Actual result

imported-ok
imported-nok
self-ok
[()]
[()]

Root cause Metta::new_loading_runner creates an empty space but doesn't import stdlib into it while it gets all standard tokens. Thus all MeTTa definitions of the stdlib are not available for the interpreted code. It affects minimal MeTTa even more serious because interpreter itself is also part of the MeTTa stdlib code.

https://github.com/trueagi-io/hyperon-experimental/blob/0c17c629dce868a3d954c2ff725e7586ac4c8a8b/lib/src/metta/runner/mod.rs#L151-L164

This should be fixed during work on https://github.com/trueagi-io/hyperon-experimental/issues/470

vsbogd commented 9 months ago

It is a blocker for minimal MeTTa work.

vsbogd commented 9 months ago

Fixed in #574