clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
practicalli-john 2020-11-01T20:57:55.007100Z

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

seancorfield 2020-11-01T21:00:46.007700Z

"take key/value pairs" -- you mean "take a map" for this use case, right?

šŸ‘ 1
seancorfield 2020-11-01T21:01:38.009100Z

And, specifically, that will accept a single argument -- a hash map. So that narrows it down to 1-arity or varargs.

alexmiller 2020-11-01T21:01:48.009500Z

Iā€™m sure you could use the new @borkdude utility to find all functions take a map :)

šŸ‘ 1
seancorfield 2020-11-01T21:02:53.010600Z

(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)

alexmiller 2020-11-01T21:03:14.011700Z

Yeah, there are very few useful functions I can think of

practicalli-john 2020-11-01T21:03:18.011900Z

I havent had a chance to 'grasp' that tool yet šŸ™‚ but seems I have just found a use for it...

seancorfield 2020-11-01T21:03:35.012600Z

But things like count work, because it takes a single argument that can have seq called on it šŸ™‚

alexmiller 2020-11-01T21:03:47.013200Z

One example I wrote up https://insideclojure.org/2020/09/30/exec-example/

borkdude 2020-11-01T21:04:03.013800Z

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

practicalli-john 2020-11-01T21:05:30.014100Z

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.

practicalli-john 2020-11-01T21:06:39.014500Z

Hmm, it seems the server isnt serving..

phronmophobic 2020-11-01T21:07:07.014800Z

this link works for me šŸ¤·

practicalli-john 2020-11-01T21:07:49.015400Z

Maybe its just the uk...

šŸ¤· 1
practicalli-john 2020-11-01T21:08:44.015700Z

It was working earlier for me, as I was reading the clj exec articles...

borkdude 2020-11-01T21:15:44.016400Z

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))

practicalli-john 2020-11-01T21:18:52.016500Z

its working again now šŸ™‚

borkdude 2020-11-01T21:37:47.016900Z

Forgot to account for docstrings etc, but even then I find only a few and only in the tests

borkdude 2020-11-01T21:41:45.017700Z

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