I'm trying to make a Guile macro taking the argument list (x0 x1 ...)
and the
body expressions as parameters and generating the following code:
---
(lambda args
(let ((x0 (list-ref args 0))
(x1 (list-ref args 1))
...)
body1 ...))
---
I have tried the following implementation:
---
(define (get-integer-sequence start count)
(assert (>= count 0))
(if (= count 0)
'()
(cons start (get-integer-sequence (+ start 1) (- count 1)))))
(define-syntax gen-proc
(lambda (x)
(syntax-case x ()
((_ vars body1 ...)
(let* ((i-count (length (syntax->datum #'vars)))
(l-seq (get-integer-sequence 0 i-count))
(l-defs (map (lambda (i var)
(list (datum->syntax #f var)
#`(list-ref args #,i)))
l-seq (syntax->datum #'vars))))
#`(lambda args (let #,(datum->syntax #f l-defs)
body1 ...)))))))
---
I have a problem with renaming the arguments xn. For example, command
(tree-il->scheme (macroexpand '(gen-proc (x1) x1))) displays
(lambda args (let ((x1-1 (list-ref args 0))) x1)).
How can I prevent renaming the variables in the let bindings?
- Tommi Höynälänmaa
--
Kotisivu / Homepage:http://www.iki.fi/tohoyn/
Sähköposti / E-Mail:[email protected]
GPG-sormenjälki / GPG fingerprint:
55F4 2477 7155 3528 5CB2 2B7A BB86 1FDE 4046 0F83
FT, Debian-ylläpitäjä / PhD, Debian Maintainer