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
Erroneous warning when using eval to apply a procedure by value rather than by name. #902
Comments
"It is an error" if the first argument to eval is not a Scheme datum value.
|
Hi Marc,
Where is this stated? This is what I can find on
Is a value (such as the value referred to by (eval (list + 1 2) (environment)) To match the following existing behavior which evaluates without warning in Chibi: (eval 1 (environment))
(let ((x 1)) (eval (list '+ x 2) (environment '(scheme base))))
((eval + (environment)) 1 2) Edit: Another interesting example without warning: ;; even? used as a procedure from the current lexical environment, but not in an application position
(eval (list 'filter even? '(list 1 2 3 4)) (environment '(only (scheme base) list) '(srfi 1))) |
R6RS, which you may want to look up, is more precise. But what is meant here is that Expressions (and definitions) are represented by Scheme datum values because this is what the Scheme (code) reader produces.
It is not an expression as defined by R7RS. Please also take a look at 4.1.2 about literal expressions.
Yes, it does fall under "implementation-specific extensions". A warning is not necessarily bad because it can help write portable programs.
The first two expressions are standard R7RS. Chibi is inconsequential by not issuing a warning for the last expression. This is due to how literal expressions are implemented. The same issue shows up in the "another interesting" example. |
PS If you need to "inject" values into an expression to be evaluated in a portable way, you can use the following idiom: ((eval '(lambda (plus) (plus 1 2)) (environment '(scheme base))) +) |
I think I understand better now :) the duality between literal expressions and their symbolic values made it seem inconsistent to me. I also just made this macro based on that pattern: (define-syntax eval-with
(syntax-rules ()
((_ (injections ...) expr env)
((eval `(lambda (injections ...) ,expr) env) injections ...))))
(eval-with (+) '(+ 1 2) (environment '(only (scheme base) lambda))) ; => 3, without warning Thank you for helping me understand! |
This macro is a clever idea! |
The above
eval
should (and does) return 3. It is essentially the same as(apply + (list 1 2))
, in the sense that+
comes from the current lexical environment, rather than theenvironment
parameter.eval
warns about an "invalid operator in application", but I don't think it should.The same error occurs whether the application is on an
opcode
or aprocedure
value.The text was updated successfully, but these errors were encountered: