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

builtins/eval throws 'frame does not exist' #244

Open
behrica opened this issue Jul 6, 2023 · 2 comments
Open

builtins/eval throws 'frame does not exist' #244

behrica opened this issue Jul 6, 2023 · 2 comments

Comments

@behrica
Copy link
Contributor

behrica commented Jul 6, 2023

(require-python '[builtins :as bt])
(bt/eval "1") 
;Execution error at libpython-clj2.python.ffi/check-error-throw (ffi.clj:708) .
; SystemError: frame does not exist

while this works

(require-python '[builtins :as bt])
(bt/eval "1" {})

while in python both work:

>>> eval('1+1')
2
>>> eval('1+1',{})
2
@jjtolton
Copy link
Contributor

jjtolton commented Jul 6, 2023

If you try from embedded mode it should work. I can't remember the trick but you need to create a base frame by running py/run-simple-string otherwise.

Footnotes:

  1. if you do (import-python) you get access to the Python namespace which will
    Let you do python/eval.

@jjtolton
Copy link
Contributor

jjtolton commented Oct 26, 2023

@behrica

(import-python)
(python/eval "1" (:globals (py/run-simple-string ""))) ;;=> 1

Black magic.

Actually...

(python/eval "1" (python/dict)) ;;=> 1

also works 🤔

You know, I gotta say, sometimes libpython-clj confuses me.

(python/eval "eval('eval(\"1\")', {\"eval\": eval})" {"eval" python/eval}) ;;=> 1

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