[gambit-list] macro problems

Adrien Piérard pierarda at iro.umontreal.ca
Thu Aug 13 07:12:15 EDT 2009


2009/8/13 lowly coder <lowlycoder at 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, 日本語, 한국어



More information about the Gambit-list mailing list