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

[Question] Is it possible/easy to implement something like this using sorcery? #8

Closed
pwwang opened this issue Nov 26, 2020 · 4 comments

Comments

@pwwang
Copy link

pwwang commented Nov 26, 2020

# turn
lambd(X.a + X.b)
# into
lambda X: X.a + X.b

Suppose X.a + X.b is some valid syntax (proxies). When it is turned into a lambda function, it becomes a valid function body and X is replaced by the argument.

This could be implemented inside lambd, and it can return the lambda function.

@alexmojaki
Copy link
Owner

Sure, you could get the source like in that recent varname issue, construct the lambda in a string, then eval it.

@pwwang
Copy link
Author

pwwang commented Nov 26, 2020

Is it possible to fetch the AST node and put/eval it in the context as a function body? I mean instead of eval the source code but the AST node. Worried about that source code could be arbitrary.

@alexmojaki
Copy link
Owner

Yes, after all you get the AST node first and get the source code from that. You can eval the node but the node contains the exact same code as the source, it's just as 'dangerous'.

@pwwang
Copy link
Author

pwwang commented Nov 26, 2020

This is implemented with executing.
Just in case if you are curious:

https://github.com/pwwang/pipedy

@pwwang pwwang closed this as completed Nov 26, 2020
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

No branches or pull requests

2 participants