如何从Clojure中的地图宏中获取宏中的参数? [英] How do I get the argument in a macro from a map macro in Clojure?

查看:119
本文介绍了如何从Clojure中的地图宏中获取宏中的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把我的宏传递给一个map操作(也是一个宏)。我有一些麻烦得到我的价值观。下面是一个例子:

I'm passing my macro to a map operation (which is also a macro). I'm having some trouble getting my values out. Here is an example:

(def num-vec [1 2 3 4 5])

(defmacro describe-args [first-arg & remaining-args]
  `(println '~first-arg '~remaining-args))

(doall (map #(describe-args "my args " %) num-vec))

这会返回:

  my args  (p1__432#)
  my args  (p1__432#)
  my args  (p1__432#)
  my args  (p1__432#)
  my args  (p1__432#)

我的问题是:如何从Clojure中的地图宏中获取宏中的参数?

(我相信这是与其他地图/宏问题不同的问题已询问这是关于参数检索)。

(I believe this is a different question to the other map/macro questions already asked as this is about argument retrieval).

推荐答案

您可以将宏 describe-args 更改为:

(defmacro describe-args [desc & args]
  `(println ~desc ~@args))

现在

(doall (map #(describe-args "my args " %) num-vec))



prints

my args  1
my args  2
my args  3
my args  4
my args  5

更多通用调试宏在answer

这篇关于如何从Clojure中的地图宏中获取宏中的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆