[plt-scheme] how to quote identifier in macro

From: Andre Mayers (andre.mayers at usherbrooke.ca)
Date: Thu Dec 11 17:14:47 EST 2008

If I quote the identifier the expression given to eval becomes 
(λ (self p1 p2)
  (let ((a1 (#<procedure:slot-value> p-attr self))
        (a2 (#<procedure:slot-value> p-attr self))
        (a3 (#<procedure:slot-value> p-attr self)))
    (display self)
    (+ p2 a1))) 

therefore the evaluation of 
((tata attr vals (self p1 p2) (display self) (newline) (+ p2 a1))  
 '((a1 10)(a2 20)(a3 30)) 4 5)
---> reference to undefined identifier: p-attr
and what I want is 
(λ (self p1 p2)
  (let ((a1 (slot-value 'a1 self))
        (a2 (slot-value 'a2 self))
        (a3 (slot-value 'a3 self)))
    (display self)
    (+ p2 a1)))
and, if I unquote it, I got
(λ (self p1 p2)
  (let ((a1 (#<procedure:slot-value> a1 self))
        (a2 (#<procedure:slot-value> a2 self))
        (a3 (#<procedure:slot-value> a3 self)))
    (display self)
    (+ p2 a1)))
The complete program is below

(define slot-value
  (λ (slot-name objet)
    (cadr (assq (quote slot-name) objet))))

(define-syntax (tata stx)
  (syntax-case stx ()
    [(_ a v (s ps ...) body ...)
;      (eval 
       (list 'λ '(self ps ...) 
                  (list* 'let (map (λ (p-attr) 
                                     (list p-attr 
                                           (list slot-value (quote p-attr)
                         '(body ...)))
 ;          (make-base-namespace))
(tata attr vals (self p1 p2) (display self) (newline) (+ p2 a1))

-----Message d'origine-----
De : Noel Welsh [mailto:noelwelsh at gmail.com] 
> My first problem is how to quote it.

Just write

(quote some-expr)

> I may have also a problem to get rid of the eval.

Just write out the program code you want in that place:

(lambda (self ps ...) ...)

Also, underscores are not really Scheme style.  Use hyphens instead.
I.e. foo-bar not foo_bar


Posted on the users mailing list.