获取Clojure参数列表 [英] Get Clojure argument list

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

问题描述

我想要的东西,给我的实际值传递给一个函数的顺序,类似于 arguments 在javascript函数中的值。

I want something that gives me the sequence of actual values passed to a function, similar to the arguments value in a javascript function.

我知道我可以使用

(defn fx [& args]
 args)

<= (fx {:a 1} 2)
=> ({:a 1} 2)

但这会删除我的函数的arity。我想要有像

But this removes the arity on my function. I want to have something like

(defn fx [{:keys [a]} b]
 (MAGIC_FUNCTION_THAT_RETURNS_THE_ARGS_VALUES))

<= (fx {:a 1} 2)
=> ({:a 1} 2)

可以获得传递给一个函数?

Is it possible to get a raw sequence of the values passed to a function?

推荐答案

到函数体执行时,参数已经被解构。您可以定义自己的 defn 宏并公开这些值。我知道Lighttable在Instarepl中显示参数值。

By the time the function body is executed, the parameters have already been destructured. You could define your own defn macro and expose those values. I know Lighttable does this in their Instarepl to show the argument values.

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

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