[plt-scheme] how to get rid of eval ; was : how to quote identifier in macro
It almost works. I don’t know how to insert the binding inside de let
---
(define attr '(a1 a2 a3))
(define slot-value
(λ (slot-name objet)
(cadr (assq slot-name objet))))
(define-syntax (tata stx)
(syntax-case stx ()
[(_ a v (s ps ...) body ...)
#'(λ (self ps ...)
`(let ,(map (λ (p-attr)
(list p-attr
(slot-value p-attr self)))
a)
body ...))
]))
((tata attr vals (self p1 p2) (display self) (newline) (+ p2 a1))
'((a1 10)(a2 20)(a3 30)) 4 5)
è
(let ((a1 10) (a2 20) (a3 30)) (display self) (newline) (+ p2 a1))
===
If I remove the quote in front of the let, I got the following error
let: bad syntax (not an identifier and expression for a binding) in: map
De : YC [mailto:yinso.chen at gmail.com]
Envoyé : December-11-08 7:29 PM
À : andre.mayers at usherbrooke.ca
Cc : pltscheme
Objet : Re: [plt-scheme] how to quote identifier in macro
On Thu, Dec 11, 2008 at 3:32 PM, Andre Mayers <andre.mayers at usherbrooke.ca> wrote:
Eureka. It works.
Now how to get rid of eval ?
As Noel said, try to write what you want as the final result, instead of using list & list* to create the expression and then eval it.
As an example, the following creates a lambda without list, list*, and eval.
(define-syntax (tada2 stx)
(syntax-case stx ()
((_ a1 a2 ...)
#'(lambda (a1 a2 ...)
(list a1 a2 ... 'a1 'a2 ...)))))
((tada2 a b c) 1 2 3) ;; => ??
HTH,
yc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20081211/ecf04e7f/attachment.html>