Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Clojure argument list

Tags:

clojure

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

I am aware that I can grab the entire function argument list using

(defn fx [& args]
 args)

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

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?

like image 871
Stephen Cagle Avatar asked Sep 14 '13 03:09

Stephen Cagle


Video Answer


1 Answers

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.

like image 189
Jared314 Avatar answered Nov 04 '22 23:11

Jared314