开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜