[plt-scheme] how to quote identifier in macro

From: Andre Mayers (andre.mayers at usherbrooke.ca)
Date: Wed Dec 10 21:47:31 EST 2008

The following program 
---

#lang scheme
(define attr '(a1 a2 a3))
(define vals '(1 2 3))

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

(define-syntax (tata stx)
  (syntax-case stx ()
    [(_ a v (s ps ...) body ...)
     (syntax 
      (eval (list 'λ '(self ps ...) 
                  (list* 'let (map (λ (p_attr) 
                                     (list p_attr (list slot-value p_attr
'self))) a) 
                         '(body ...)))
            (make-base-namespace)))]))

((tata attr vals (self p1 p2) (display self) (newline) (+ p2 a1))  '((a1
10)(a2 20)(a3 30)) 4 5) 
===
give the following result
---
. . reference to undefined identifier: a1
===
It is the expected result because the expression given to eval is 
(λ (self p1 p2)
  (let ((a1 (#<procedure:slot-value> a1 self))
        (a2 (#<procedure:slot-value> a2 self))
        (a3 (#<procedure:slot-value> a3 self)))
    (display self)
    (newline)
    (+ p2 a1)))

and the ai in (#<procedure:slot-value> ai self) is not quoted. 

My first problem is how to quote it. 

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

Any help will be appreciated. 

André Mayers, Ph.D., M. Ps.
professeur agrégé
Département d'informatique
Université de Sherbrooke
Sherbrooke (Québec) Canada J1K 2R1
tél: +1 819-821-8000 poste 62041
fax: +1 819-821-8200
andre.mayers at usherbrooke.ca
http://www.dmi.usherb.ca/~amayers




>




Posted on the users mailing list.