Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding mod-space! Op Atom, to access the space of a module, loading it if necessary #615

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

luketpeterson
Copy link
Contributor

@luketpeterson luketpeterson commented Mar 10, 2024

Adding mod-space! Op Atom, to access the space of a module, loading it if necessary
See #592

It's now possible to do this: !(add-atom &new_space (mod-space! mod_name))

Therefore, !(add-atom &self (mod-space! stdlib)) adds the same atom(s) as !(import! &self stdlib), but does not add any tokens.

For me the remaining question is whether we want to enshrine the "nested-sub-space" behavior into MeTTa semantics? We could add a merge-atoms or similar operation, to make it clear we're bringing in all atoms from the source space, but the implementation in the present code would be identical to add-atom

Copy link
Collaborator

@Necr0x0Der Necr0x0Der left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking into account that modules drift away from pure spaces as was supposed, mod-space operation makes sense. I wonder if it has to have side effects, though. Do we need to load the module if it is not loaded, or would it be better to return Empty?

@luketpeterson
Copy link
Contributor Author

Taking into account that modules drift away from pure spaces as was supposed...

The biggest conceptual issue here is the Tokenizer. There are other minor things, but if we can come up with a way the Tokenizer leverages the space then I am sure we can solve the rest of the issues. #510 Of course the Alpha release timeline might constrain us a bit.

Do we need to load the module if it is not loaded, or would it be better to return Empty?

Not sure. My assumption was that load-on-demand would be more convenient. Otherwise people would need to use register-module! or import! prior. Which might be inconvenient. Especially because import! does additional stuff (e.g. registering tokens) and register-module! works with paths and therefore is limited to modules in the file system.

@Necr0x0Der
Copy link
Collaborator

My assumption was that load-on-demand would be more convenient.

Maybe, this functionality should be covered by a unit test.

@luketpeterson
Copy link
Contributor Author

Maybe, this functionality should be covered by a unit test.

The Op Atom generally has this unit test: https://github.com/luketpeterson/hyperon-experimental/blob/b686aa950964c089621a6ad5a60ea46e2d2cc799/lib/src/metta/runner/stdlib.rs#L1527

as far as a unit test specifically for load-on-demand, it calls through exactly the same pathway as import!, so I don't think there is much untested surface area in that particular interaction.

@luketpeterson luketpeterson merged commit f867494 into trueagi-io:main Mar 11, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants