This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-01
Channels
- # babashka (1)
- # beginners (28)
- # calva (28)
- # cider (8)
- # clj-kondo (1)
- # clojars (4)
- # clojure (20)
- # clojure-australia (1)
- # clojure-europe (13)
- # clojure-uk (2)
- # clojurescript (2)
- # conjure (4)
- # core-async (4)
- # cryogen (3)
- # datomic (17)
- # fulcro (3)
- # helix (45)
- # malli (9)
- # off-topic (6)
- # pathom (3)
- # re-frame (13)
- # reitit (17)
- # sci (1)
- # shadow-cljs (9)
- # sql (6)
- # tools-deps (11)
- # vim (17)
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
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/
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 🤷
It was working earlier for me, as I was reading the clj exec articles...
its working again now 🙂
served off of github so ... ¯\(ツ)/¯
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
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))
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