-
Notifications
You must be signed in to change notification settings - Fork 216
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
[Feature Request] Share Caller Context (_jac_here_) with non node abilities if called from within walker #1347
Comments
Yes, this request makes sense. @kugesan1105 @ypkang @amadolid The way I would sovle this is a bit of a rearchitecture of how jac_here works. Instead of codegen producing abilities that pass the relevant object to abilities, I would create 2 new jac_rtlib (pluggin) interface for walker_here() and node_here() and codegen would resolve teh keyword to make calls to either Jac.walker_here() and Jac.node_here() in the bodies of abilities which would take no variables. This would work as a solution for this request. HOWEVER @ChrisIsKing This is an interesting design decision in that if a method is called outside of the context of a walk the usage of |
@marsninja The thinking is that the onus is on the developer to know if the function they are calling is data spacial or not. In the above example, a dev can still call an ability outside the context of a walk. e.g
Similarly, this will fail with the error A quick workaround I'm willing to accept is possibly a naming convention for functions we want to have inherit the caller context, possibly something like |
Ok, the good news is its very implementaable to make JacFeature.here() work dynamically, for now you can always make the walker/node a parameter of the methods. We can discuss more in person. |
Hey @ChrisIsKing been thinking about this, and I have a proposal of some syntax that maintains semantic separation between data spatial abilities and traditional methods. How about something like
Where we can have this work however there is the sytax change on the What do you think @ChrisIsKing? |
@marsninja I'm fine with this syntax change if it's a quick fix. I love the idea of using Who should we assign this interim fix to? |
@ChrisIsKing actually it would be a quick change, it would just require code updates in all jac programs created with prior versions. I can go either way, the best path forward would probrably to give warnings of deprecation for a while. I'm down for the def / can swap. @ypkang @eldonm What are your thoughts? on using can only for abilities and using def for tradtional methods in jac. |
So building on the thread where I see we're in agreement of distinguishing between "data spatial" and "traditional" methods/abilities. The 'def' vs 'can' are still too similar to one another and may present a situation whereby it's less than intuitive to new devs. Data spatial abilities do not need to be callable from outside the walker like a traditional method, they simply define the spatial context within which the walker should execute a block of code. I suggest we bring back (as best as we can) the code block used in JAC 1 with some adjustments. Eg.
|
How about just declare We can also assign it for node and edge to reference current walker in the same loop. We can even put it on anchors |
@amadolid this works and we won't need the 'visitor' proposed. I'd still like to see a dedicated construct equivalent to code blocks in JAC 1, however. Using abilities for the sole purpose of controlling walker behaviour as it walks forces us to come up with clever ability names which we'll never need to call like a regular ability. I've begun using a convention like 'on_[node name]' e.g.
We'll never need to call these like regular abilities so it'll be cleaner to distinguish this construct from regular abilities with safeguards to ensure they're not called / used like regular abilities... something like :
It reads better too.. |
@eldonm that looks clean. If it's optional to use, I think that's good to have walker graph_walker {
on `root entry {
visit [-->](`?app);
}
on app entry {
visit [-->](`?agents);
}
} The reason I ask if it's optional because there's a scenario you want to segregate process walker graph_walker {
can initialize_exit with `root exit {
# prepare for cleanup
}
can actual_cleanup with `root exit {
# do some cleanup
}
can finalize_cleanup with `root exit {
# finalize cleanup
}
} This should be triggered in order but in the same |
@amadolid yes, definitely optional; we'd still want to use abilities as shown, where applicable.. I'm 100% on what you've suggested, let's get it! |
@marsninja thoughts? Looks like we want to move ahead with:
|
@eldonm The names would be needed for inheritance, if you wanted a derived class type to reimplement some ability functionality it would need to be named.
how would you reason about overriding these abilities say you wanted to add a separate functionality for execution on root nodes, and have it be override-able in subclasses? |
@ChrisIsKing lets keep discussing for a moment. So far I'm closer to agreement on the special data spatial syntax to support abilities that are triggered only by calling from other abilities, along with the separation on can/def. The reason I prefer that separation @eldonm and folks is basically all can's in that case would have the Also @ChrisIsKing, I believe we'd ultimately want to keep the names on all abilities to be orthogonal to inheritance semantics as we'd have to create a bunch of new language rules as to what happens whne you derive classes from base classes with, lets call it anonymous abilities. Any thoughts there? |
@ChrisIsKing can you add a task of documenting how abilities work to @TharukaCkasthuri's documentation roadmap doc and plan when we can have a V1. We need to capture the semantics of abilities in to documentation? |
@marsninja I sent the info over to Randi. In the interim while we discuss the syntax around abilities and methods, can we support the addition of making |
@marsninja Following up on this |
@marsninja and @ChrisIsKing I'm working on adding a complete abilities example and documentation in the |
Describe the feature you'd like
This feature request aims to allow non-abilities in nodes to have access to the caller context (jac_here) when invoked from within a walker. Currently, the
_jac_here_
context is unavailable in non-ability functions, causing errors when trying to reference caller variables.In many cases, a walker may need to perform some preparatory logic before deciding whether to invoke a node’s ability. During this process, it may trigger a node function that is not defined as an ability. Ideally, when this function is invoked, it should have access to the walker's context (
here
) by default—just like an ability does—so that the caller context is consistently available without needing to pass it as an explicit parameter or refactor the function into an ability.Currently, this limitation forces developers to either:
here
) explicitly as a parameter, which can complicate the code.The proposed feature would remove these workarounds and streamline the walker’s logic by ensuring that any function triggered during its execution inherits the caller’s context (
here
), making development more intuitive and reducing unnecessary complexity.Examples
Using this code snippet as an example:
Running the above code will result in the following error:
In this case, before the walker decides to invoke the
modify_value ability
on test_node, it performs some checks (e.g., if (here.access
)). When the non-abilitymodify_value
function is called, it does not have access tohere
, resulting in the error.With the proposed feature,
here.value
would be accessible in the function, allowing it to execute successfully without the need to passhere
as a parameter or convertmodify_value
into an ability. This would streamline the process and maintain logical flow without requiring extra coding steps.The text was updated successfully, but these errors were encountered: