开发者

If I have: (apply f '(x1 x2 x3 .... xn)) and I'd like to change it to a macro expansion

开发者 https://www.devze.com 2022-12-20 21:43 出处:网络
I have (apply f\'(x1 x2 x3 .... xn)), and I\'d like to change it to a ma开发者_如何学Ccro expansion: (f x1 x2 x3...xn). What kind of problems can occur?If you\'re just converting

I have (apply f '(x1 x2 x3 .... xn)), and I'd like to change it to a ma开发者_如何学Ccro expansion: (f x1 x2 x3...xn). What kind of problems can occur?


If you're just converting

(define (my-apply f args)
   (apply f args))

to

(define-macro (my-other-apply f args)
   `(,f ,@args))

then it seems to be simple enough. The biggest pitfall in this situation is that you'd have to remember not to quote the list you pass to the macro.

>(my-apply + '(1 2 3))
>6

>(my-other-apply + '(1 2 3))
>ERROR syntax-error: "(+ quote 1 2 3)"

>(my-other-apply + (1 2 3))
>6
0

精彩评论

暂无评论...
验证码 换一张
取 消