Home > Archive > Scheme > November 2007 > avoiding eval in macro
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
avoiding eval in macro
|
|
| Holubar 2007-11-03, 7:12 pm |
| Hello!
First of all thanks to all who responded to my last message.
The additional input really helped a lot.
I am, however, stuck with a variation of the same problem:
eliminating "eval" from a macro.
The problem:
I do have attribute lists like for example
(define atts '((left . 0) (top . 0) (width . 400) (height . 100)))
Now I want to bind selected values to their symbols to be able to
operate easily on them. Like:
(with-attributes '(left height) atts (display height))
["left" should be bound, too - "top" and "width" shouldn't]
This currently works well with the following macro I wrote:
[find-attribute either returns the attribute or raises an error when not
found]
(define-syntax with-attributes
(syntax-rules ()
((_ sym-list arg-list body...)
(eval
`((lambda ,(map (lambda (x) x) sym-list)
body...)
,@(map (lambda (x) (find-attribute x arg-list)) sym-list))))))
But I'm not really happy with the use of "eval". Unfortunately I cannot
think of any way to eliminate it. Help would be greatly appreciated.
Many thanks in advance!
Thomas
--
Delete all 'n' to respond via eMail.
| |
| Abdulaziz Ghuloum 2007-11-03, 7:12 pm |
| Holubar wrote:
> ...
> (define-syntax with-attributes
> (syntax-rules ()
> ((_ sym-list arg-list body...)
> (eval
> `((lambda ,(map (lambda (x) x) sym-list)
> body...)
> ,@(map (lambda (x) (find-attribute x arg-list)) sym-list))))))
>
> But I'm not really happy with the use of "eval". Unfortunately I cannot
> think of any way to eliminate it. Help would be greatly appreciated.
Something like this?
(define-syntax with-attributes
(syntax-rules ()
((_ names arg-list body body* ...)
(let ((args arg-list))
(let ((names (find-attribute names args)) ...)
body body* ...)))))
(with-attributes (left right) atts
(display (list left right)))
Notice here that attributes' names is not a run time
value, it's just a list of names (no quote before it).
Aziz,,,
|
|
|
|
|