Without reading through 7892 lines of code that makes up the clojure.core namespace, how can I tell which of those function would take key/value pairs?
I am trying to find out which clojure.core functions (or anything from the Clojure standard library) I can call on the command line using Clojure exec.
e.g. clojure -X clojure.pprint/pprint :functions 569 :macros 62 :execfn 2
"take key/value pairs" -- you mean "take a map" for this use case, right?
And, specifically, that will accept a single argument -- a hash map. So that narrows it down to 1-arity or varargs.
Iām sure you could use the new @borkdude utility to find all functions take a map :)
(I think it's a much smaller list of functions than you might imagine since most things that operate on a map, tend to take at least one other argument)
Yeah, there are very few useful functions I can think of
I havent had a chance to 'grasp' that tool yet š but seems I have just found a use for it...
But things like count
work, because it takes a single argument that can have seq
called on it š
One example I wrote up https://insideclojure.org/2020/09/30/exec-example/
hmm, how can you, by looking at the form, infer that a function takes a map? I guess you can look at keys destructuring. but for example prn
also takes a map
the site is down, did you do an update in the last half hour. I was just looking at the clj articles.. will try again.
Hmm, it seems the server isnt serving..
this link works for me š¤·
Maybe its just the uk...
It was working earlier for me, as I was reading the clj exec articles...
I only find two functions in all of Clojure's source with keys destructuring in the first argument and those are in the tests:
$ grasp ~/git/clojure -e "(g/seq 'defn symbol? (g/vec (s/keys :req-un [::keys]) (s/* any?)) (s/* any?))"
file:/Users/borkdude/git/clojure/test/clojure/test_clojure/special.clj:105:5
(defn foo
[{:keys [^String s]}]
(.indexOf s "boo"))))
file:/Users/borkdude/git/clojure/test/clojure/test_clojure/transducers.clj:149:1
(defn result-good?
[{:keys [s xs xi xe xt]}]
(= s xs xi xe xt))
its working again now š
Forgot to account for docstrings etc, but even then I find only a few and only in the tests
if we're looking for keys destructuring in any position:
$ grasp ~/git/clojure/src/clj/clojure -e "(s/def ::keys-arg (s/keys :req-un [::keys])) (g/seq 'defn (s/* any?) (g/vec (s/* any?) ::keys-arg (s/* any?)) (s/* any?))" | grep file:
file:/Users/borkdude/git/clojure/src/clj/clojure/core/server.clj:191:1
file:/Users/borkdude/git/clojure/src/clj/clojure/core/server.clj:272:1
file:/Users/borkdude/git/clojure/src/clj/clojure/core/server.clj:295:1
file:/Users/borkdude/git/clojure/src/clj/clojure/main.clj:584:1
This is only for single-arity fns, but you get the gist