You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Functions defined on the struct are bidden to the Env they were compiled with #695
If I understood correctly, what you trying to achieve you can try this approach: create a function which will be bidden to and env outside of expr. Use expr.Function to call it.
This way you can achieve fastest calling speed and preserve bindings.
I will try to write some code when I can reach my computer
The program I've shared gives a good example of what I am trying to achieve:
Compile a program once and then run it with different struct envs.
Functions must have access the current/running env, because I don't have vars and use getter functions instead. It is much more flexible this way.
Currently I am patching functions to pass $env as the first arg. It would be nice if expr-lang could detect this and pass it automatically, i.e. support functions with this signature:
Activity
antonmedv commentedon Aug 9, 2024
This is intended behaviour. You passed env.Get to Function:
expr.Function("get", env.Get, new(func() any)),
In Golang this makes reciver argument bidden to env. You can simplify your code and do not use expr.Function and use methods on env directly.
Please, try this approach and see if it works.
vmihailenco commentedon Aug 9, 2024
But it will be slower and I can't use type hints to get helpful error message, right? It is not the trade-off I am willing to make...
antonmedv commentedon Aug 10, 2024
It will be just a bit slower. Types will be inherited.
antonmedv commentedon Aug 10, 2024
If I understood correctly, what you trying to achieve you can try this approach: create a function which will be bidden to and env outside of expr. Use expr.Function to call it.
This way you can achieve fastest calling speed and preserve bindings.
I will try to write some code when I can reach my computer
vmihailenco commentedon Aug 10, 2024
The program I've shared gives a good example of what I am trying to achieve:
Currently I am patching functions to pass
$envas the first arg. It would be nice if expr-lang could detect this and pass it automatically, i.e. support functions with this signature:antonmedv commentedon Aug 10, 2024
This is a nice idea. Expr already has patcher for context. We can have a patcher for env as well.