[plt-scheme] how to quote identifier in macro

From: Andre Mayers (andre.mayers at usherbrooke.ca)
Date: Fri Dec 12 17:22:03 EST 2008

Thank you Noel for the time spent to debug my program.
Sorry for not reacting more quickly, I had some urgent matter to settle. 
The code that I shown was extracted and modified from a more complex program, a kind of object programming language. 
(define attr '(a1 a2 a3))
; attr is a list of slot name.
; attr is the concatenation of the slot of the current class and the slots of its superclass.
; As define-class is a macro, it is possible to know them at expansion time
; but we don't have a syntaxical form (a1 ...) = attr 

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

(define-syntax (tata stx)
  (syntax-case stx ()
    [(_ a (s ps ...) body ...)
     #'(λ (self ps ...) 
           `(let ,(map (λ (p-attr) 
                        (list p-attr 
                         (slot-value p-attr self)))
                 body ...))

; the syntaxical form (tata a (s ps ...) body ...) should return a procedure
; for example
(tata attr 
      (self p1 p2) 
      (display self) (newline) (+ p2 a1))
; should return
(λ (self p1 p2)
  (let ((a1 (slot-value 'a1 self))
        (a2 (slot-value 'a2 self))
        (a3 (slot-value 'a3 self)))
    (display self)
    (+ p2 a1)))
; therefore 
; a = attr has been described in the beginning of this email
; (s ps ...) = (self p1 p2) is a list of identifiers known at expansion time
; body ... = (display self) (newline) (+ p2 a1) 
;            is the body of the let and is known at expansion time
; self is just an identifier at expansion time
; therefore it is not possible to know the value of (slot-value 'a1 self) 
; at expansion time

at execution time, we may have the following expression
(<proc-tata>  '((a1 10)(a2 20)(a3 30))  4  5) 
; <proc-tata>  îs the compiled version of the procedure created by tata
; ((a1 10)(a2 20)(a3 30)) is a simplified example of the object self
; slot-value of a1 is 10 ....
; 4 5 are others parameters of <proc-tata>  

Posted on the users mailing list.