-
Notifications
You must be signed in to change notification settings - Fork 43
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
case cannot be used with function calls defined out of the case metta module scope #354
Comments
unify* does not work yet due to issues trueagi-io/hyperon-experimental#242 and trueagi-io/hyperon-experimental#354 It should be noted that even the let/let* variant is bound to eventually fail due to issue 242 (because sooner or later a pattern may unify with a function definition in the current atomspace), but it buys use some time because at least let* cannot be unified with anything due to being hard coded at the rust level.
As the space into which pure function is passed as an atom doesn't import the space where the function is defined we cannot execute pure function in it properly. In order to execute the passed pure function we need to have a reference to the space where the function is defined. Usually this issue is not visible because top-level interpreter works on top-level space which imports all other spaces and thus search of the atom in top-level space brings all needed results. In case from the issue description the search starts from the top level space from which |
The current behavior is essentially correct for This situation is where an |
include
operation needed to access external functionality within the metta module's scope
I am not sure if you mean this but |
I don't follow what you are saying... The term "pass into" is confusing me because modules don't explicitly declare any export directives. So any item used must be imported or included by the module that intends to use it. If we have something like this:
B.metta
C.metta
Then you would get the expected (correct) result. |
Its vice versa. I mean something like this (the example is highly unnatural):
B.metta:
C.metta:
Actually it doesn't even matter whether is chain consists of three or two modules. It indeed works if we replace |
I have very similar issue with I am thinking about adding |
Sorry I misunderstood. It's basically environment-capture (closure) behavior that we want. |
include
operation needed to access external functionality within the metta module's scope
With the fix in #643 you can access |
Part 1: I want to describe what’s happening (I know you already know this @vsbogd , but this will help synchronize terms for the ongoing discussion)
Part 2: what solution do we want - from a language usability perspective?
synthesize.metta
bug.metta
You can try it out with #644 |
If we like this pattern but not the name "capture", other options are "close", "enclose", "context", "ctx", etc. |
It is absolutely equal to my understanding and minimal MeTTa allows doing this without evaluating expressions inside |
Adding "capture" operation. Experimental approach to issue #354
I merged #644 because it introduces a nice functionality. On the other hand to me it still doesn't resolve the issue completely because to use this solution the user should pass the context manually. I was thinking about passing the context automatically but I am not sure what is the best way to implement it. |
I'm not sure that's always desirable to automatically capture the caller's context. Because it might make it impossible to implement functions that are intended to work within the context of the sub-module. |
It is interesting case but usually passed function gets all inputs from the caller via arguments, thus I would say this case is rare. May be we could vice versa add a manual way to make functions which can be embedded into foreign context. |
When
case
calls the passed function in the imported module, for example (synthesize.metta
):and it is called from importing module, where function is passed as an argument (
bug.metta
):case
cannot call the passed function because this function is defined in the outer module whilecase
runs interpreter with space of the module where the call of thecase
is defined.Expected result:
[(: f (-> Number String))]
Actual result:
[]
The text was updated successfully, but these errors were encountered: