(define foo 2) (pp (eval 'foo)) (define-macro (test) (define bar 3) (pp (eval 'bar))) ;(test) why does (test) fail? it confuses me why the eval works in foo but not in bar Thanks!
Afficher les réponses par date
The following confuses me even more: (define-macro (test) (define bar 3) (pp (eval '(+ 1 2))) (pp bar) (pp (eval 'bar))) (test) On Thu, Aug 13, 2009 at 2:39 AM, lowly coder<lowlycoder@huoyanjinjing.com> wrote:
(define foo 2) (pp (eval 'foo))
(define-macro (test) (define bar 3) (pp (eval 'bar)))
;(test)
why does (test) fail? it confuses me why the eval works in foo but not in bar
Thanks!
2009/8/13 lowly coder <lowlycoder@huoyanjinjing.com>:
The following confuses me even more:
You are mixing environments…
(define-macro (test) (define bar 3)
Bar is defined in the body of the macro
(pp (eval '(+ 1 2)))
No bindings here, no problem
(pp bar)
This is bound to 3
(pp (eval 'bar)))
This bar is in another world. Try to add the second parameter to eval (the environment), just to be sure
(test)
fail. In other words, look at that (define-macro (foo) (define bar 3) (eval '(define bar "hi")) (pp bar) (eval '(pp bar))) (foo) See the point? P! -- Français, English, 日本語, 한국어
Why does the following work? (define foo 2) (pp (eval 'foo)) ; --> 2 ? (sorry for my ignorane) On Thu, Aug 13, 2009 at 3:27 AM, Adrien Piérard<pierarda@iro.umontreal.ca> wrote:
2009/8/13 lowly coder <lowlycoder@huoyanjinjing.com>:
The following confuses me even more:
You are mixing environments…
(define-macro (test) (define bar 3)
Bar is defined in the body of the macro
(pp (eval '(+ 1 2)))
No bindings here, no problem
(pp bar)
This is bound to 3
(pp (eval 'bar)))
This bar is in another world. Try to add the second parameter to eval (the environment), just to be sure
(test)
fail.
In other words, look at that (define-macro (foo) (define bar 3) (eval '(define bar "hi")) (pp bar) (eval '(pp bar)))
(foo)
See the point?
P!
-- Français, English, 日本語, 한국어
2009/8/13 lowly coder <lowlycoder@huoyanjinjing.com>:
Why does the following work?
(define foo 2) (pp (eval 'foo))
; --> 2
?
(sorry for my ignorane)
Because you are not in a macro. Here, you just have the runtime environment. In a macro, you mix the (current) macro environment, and the expansion environment. ;;; current macro env sample (define-macro (test-left) (define x 3) ;; currently known (pp x)) (define-macro (test-right) (pp x)) ;; error, x is not known (test-left) (test-right) ;;; expansion environment sample (define-macro (test-up) (eval '(define y "foo"))) (define-macro (test-down) (eval '(pp y))è ;; works (test-up) (test-down) P! -- Français, English, 日本語, 한국어
This bar is in another world. Try to add the second parameter to eval (the environment), just to be sure
What are you referring to here? According to gambit-c.txt, the second parameter, [ENV] is ignored. -- procedure: eval EXPR [ENV] The first parameter is a datum representing an expression. The `eval' procedure evaluates this expression in the global interaction environment and returns the result. If present, the second parameter is ignored (it is provided for compatibility with R5RS). For example: > (eval '(+ 1 2)) 3 > ((eval 'car) '(1 2)) 1 > (eval '(define x 5)) > x 5
An alternative solution to this is: Given (define foo ...) and "foo", is there a function that will map "foo" to the function foo is defined to? There's string->symbol but not symbol->definition Thanks! On Thu, Aug 13, 2009 at 3:44 AM, lowly coder<lowlycoder@huoyanjinjing.com> wrote:
This bar is in another world. Try to add the second parameter to eval (the environment), just to be sure
What are you referring to here? According to gambit-c.txt, the second parameter, [ENV] is ignored.
-- procedure: eval EXPR [ENV] The first parameter is a datum representing an expression. The `eval' procedure evaluates this expression in the global interaction environment and returns the result. If present, the second parameter is ignored (it is provided for compatibility with R5RS).
For example:
> (eval '(+ 1 2)) 3 > ((eval 'car) '(1 2)) 1 > (eval '(define x 5)) > x 5
2009/8/13 lowly coder <lowlycoder@huoyanjinjing.com>:
What are you referring to here? According to gambit-c.txt, the second parameter, [ENV] is ignored.
Many other schemes do not ignore it, and *want* it. That forces you to know where the side effects will happen. I wish gambit would then not ignore it (whatever default is chosen when not given). P! -- Français, English, 日本語, 한국어
participants (2)
-
Adrien Piérard -
lowly coder