-
Notifications
You must be signed in to change notification settings - Fork 83
Description
There can be various automations and syntactic sugar to make Python-MeTTa integration more convenient and pretty.
A few ideas for starters:
- Introduce
@groundeddecorator for extensions. Currently,@register_tokensdecorates a function, which returns a token-atom map. For simple cases, when we want to have a grounded function, which token and representation in MeTTa correspond to its name in Python, and it is a pure Python function withunwrap=True, we could decorate it directly, i.e.
@grounded
def sum_squares(xs):
arr = jnp.array(xs)
return int(jnp.sum(arr*arr))instead of
def sum_squares(xs):
arr = jnp.array(xs)
return int(jnp.sum(arr*arr))
@register_atoms
def def_atoms():
return {
'sum_squares': OperationAtom('sum_squares', sum_squares)
}Not sure if it is useful only for extensions, or there can be some sense in having a similar decorator in the main Python script.
- It would be useful to make a backward import of MeTTa functions to Python. Something like
metta = MeTTa()
metta.run('''
(= (my-function $xs) ...)
'''
)
# metta.import2py('my-function')
metta.my_function(...)That is, importing MeTTa functions to Python can be done by creating methods in metta object. Or, maybe, there are other ways to make calling MeTTa functions from Python more convenient.
-
MyOperationAtom([1, 2, 3])as a syntactic sugar forE(MyOperationAtom, ValueAtom([1, 2, 3])). -
Convenient access to grounded atoms defined in
mettafrom Python. Currently, if the atom is not created in a Python script and put into a variable (MyOperationAtom = OperationAtom(...)), it is very inconvenient to call it from MeTTa. It typically requires parsing from textual representation withmetta.runormetta.parse*. It would actually be nice to have them readily accessible as Python objects. Maybe, something likemetta.stdlib.randintor whatever.