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

Should eval use the top-level environment? #652

Closed
jcguu95 opened this issue Mar 12, 2024 · 1 comment
Closed

Should eval use the top-level environment? #652

jcguu95 opened this issue Mar 12, 2024 · 1 comment

Comments

@jcguu95
Copy link

jcguu95 commented Mar 12, 2024

Thanks for creating mal!

I'm playing with your python implementation. I'm a bit confused with the following behavior.

(do 
  (def! x 0) 
  (let* (x 10000) 
    (eval 'x))) ; => 0

In the python implementation stepA, eval always refers to the global environment repl_env. The source code is the following.

repl_env.set(types._symbol('eval'), lambda ast: EVAL(ast, repl_env))

QUESTION Is this intended behavior? In both emacs-lisp and common-lisp, the equivalent code yields 100.

(progn 
  (defvar x) 
  (setf x 0) 
  (let ((x 10000)) 
    (eval 'x))) 
; => 10000
@jcguu95
Copy link
Author

jcguu95 commented Mar 12, 2024

Sorry, I overlooked. It's specified in one test tests/step6_file.mal.

;; Checking that eval does not use local environments.
(def! a 1)
;=>1
(let* (a 2) (eval (read-string "a")))
;=>1

I wonder why this design though.

@jcguu95 jcguu95 closed this as completed Mar 12, 2024
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

1 participant