trueagi-io / hyperon-experimental

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

py-atom problem with multiply import #664

Closed astroseger closed 3 months ago

astroseger commented 3 months ago

The following code fails:

!(bind! random (py-atom numpy.random))
!(bind! numpy (py-atom numpy))

!( (py-dot random rand)  5)
!( (py-dot (py-dot numpy random) rand)  5)

with the following error:

[()]
[()]
[array([0.33314138, 0.87771327, 0.6544505 , 0.82240264, 0.78362403])]
[((py-dot (Error (py-dot <module 'numpy' from '/home/user/.local/lib/python3.10/site-packages/numpy/__init__.py'> <module 'numpy.random' from '/home/user/.local/lib/python3.10/site-packages/numpy/random/__init__.py'>) Exception caught:
RuntimeError: Failed to find "<module 'numpy.random' from '/home/user/.local/lib/python3.10/site-packages/numpy/random/__init__.py'>"

At:
  /home/user/hyperon-experimental/python/hyperon/stdlib.py(164): find_py_obj
  /home/user/hyperon-experimental/python/hyperon/stdlib.py(173): get_py_atom
  /home/user/hyperon-experimental/python/hyperon/stdlib.py(180): do_py_dot
  /home/user/hyperon-experimental/python/hyperon/atoms.py(404): execute
  /home/user/hyperon-experimental/python/hyperon/atoms.py(196): _priv_call_execute_on_grounded_atom
  /home/user/hyperon-experimental/python/hyperon/runner.py(201): run
  /home/user/hyperon-experimental/python/hyperon/metta.py(35): main
  /home/user/.local/bin/metta(8): <module>
) rand) 5)]

In the same case independently these two example work.

!(bind! random (py-atom numpy.random))
;!(bind! numpy (py-atom numpy))

!( (py-dot random rand)  5)
;!( (py-dot (py-dot numpy random) rand)  5)

or

;!(bind! random (py-atom numpy.random))
!(bind! numpy (py-atom numpy))

;!( (py-dot random rand)  5)
!( (py-dot (py-dot numpy random) rand)  5)
Necr0x0Der commented 3 months ago

Yes, this code is quite questionable

!(bind! random (py-atom numpy.random))
!(bind! numpy (py-atom numpy))

!( (py-dot random rand)  5)
!( (py-dot (py-dot numpy random) rand)  5)

You create random token and also wants to use it as a symbol. You shouldn't do this.

Necr0x0Der commented 3 months ago

In this string !( (py-dot (py-dot numpy random) rand) 5) random got substituted with numpy.random module.