clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
alexmiller 2021-05-31T01:26:38.175300Z

If you have main-opts in any of those aliases, then they are winding up in the wrong order

alexmiller 2021-05-31T01:27:05.176200Z

Better in that case to pass the jvm system property version of that flag using -J

alexmiller 2021-05-31T01:29:02.176900Z

-J-Dclojure.main.report=stderror

p-himik 2021-05-31T08:08:25.183400Z

Yeah, that's what I ended up doing, thanks.

svt 2021-05-31T04:27:43.179300Z

I want to intercept all incoming calls in my application, for incoming calls I’m using ring and for making outgoing calls I’m using clj-http, what is the preferred way to do it?

dpsutton 2021-05-31T05:08:24.181Z

For ring the standard pattern is middleware. For outbound my first solution would be to make a namespace that exposes vars that do whatever else needs to be done around calls to clj-http

indy 2021-05-31T05:08:52.181100Z

What is the goal? For intercepting incoming calls you could use a ring middleware. For outgoing calls you could wrap the clj-http client with your logic and use a https://github.com/dakrone/clj-http#custom-middleware there too.

Lyderic Dutillieux 2021-05-31T06:57:08.181800Z

Hey, I would like to start a clojure analysis tool. I need to parse clojure code and metadata. Would you recommend writing a specific parser myself, or is there an already existing generic parser that I can build onto?

Lyderic Dutillieux 2021-05-31T07:05:30.181900Z

I think I'll use carocad/parsera

2021-05-31T07:46:55.182100Z

https://github.com/borkdude/edamame

Lyderic Dutillieux 2021-05-31T08:39:12.183600Z

Wonderful, thanks! Exactly what I needed

Nom Nom Mousse 2021-05-31T08:06:11.183300Z

How can I make Clojure print seqs as vecs (`("hi") -> ["hi"]`) so that I can easily copy-paste them into the REPL?

magra 2021-06-01T09:25:26.238700Z

Since I have seen you in the cider channel, there is clojure-convert-collection-to-vector, normally bound to C-c C-r [

Nom Nom Mousse 2021-06-01T09:44:31.239300Z

Thanks!

Nicolas Estrada 2021-05-31T09:21:20.184300Z

Hi, anyone know how to enforce required options (ie. not missing) with tools.cli?

Nicolas Estrada 2021-06-01T08:18:34.234200Z

@seancorfield I heard through the grapevine that you are the one maintaing tools.cli? Any thoughts?

seancorfield 2021-06-01T15:30:43.252600Z

Look in the tools.cli category on http://ask.clojure.org — there have been discussions about this recently.

Nicolas Estrada 2021-06-03T14:04:38.332400Z

Thanks, I used the :missing keyword and it worked just fine, that one was missing from the README or example, but was in the doctstring! Thanks!

Nicolas Estrada 2021-05-31T09:22:39.185Z

Or must they be required as positional arguments

2021-05-31T10:17:57.185200Z

could be a combination of :default and :validate {:default ::not-present :validate [#(not= % ::not-present) "Required option!"]}

alexmiller 2021-05-31T12:38:31.185600Z

it might be easier to instead just ' the data structure that you copy

Nicolas Estrada 2021-05-31T13:08:00.185800Z

I've tried :validate and :validate-fn but they don't seem to be invoked for the value specified by the :default key

Nicolas Estrada 2021-05-31T13:09:57.186Z

I guess options are really optional 😅 I'll have to do my validation without resorting to the :errors key

Nicolas Estrada 2021-05-31T13:10:22.186200Z

Is there an issue tracker for https://github.com/clojure/tools.cli?

souenzzo 2021-05-31T13:26:43.186700Z

@nicolas.estrada938 just report on http://ask.clojure.org or in #tools-deps channel. If required, Alex should open a ticket.

🙏 1
craftybones 2021-05-31T13:28:17.187400Z

Is there any conceivable reason that a reductions like fn can’t have an equivalent transducer version?

2021-05-31T13:29:57.188600Z

they can but it has a strong dependency on the usecase for example:

(defn xf-reductions
  "Stateful transducer that mimics clojure.core/reductions.

  DIFFERENCE:
    1. There is no one-arity form.
    2. init value will not be added to the reductions list as already known."
  [f init]
  (fn [xf]
    (let [acc (volatile! init)]
      (fn
        ([] (xf))
        ([result] (xf result))
        ([result input]
         (let [res (f @acc input)]
           (vreset! acc res)
           (xf result res)))))))

craftybones 2021-05-31T13:30:36.188800Z

@delaguardo - right. Exactly as I was thinking about it.

craftybones 2021-05-31T13:31:02.189Z

Every stateful transducer then can be written in these terms right? As in, aren’t all stateful transducers, reductions essentially? Or do I have this wrong?

2021-05-31T13:33:29.189200Z

I can’t say “every” but most of them can be written like that. And I think the only problem with reductions not having transducer equivalent is only because of it’s interface.

craftybones 2021-05-31T13:35:04.189400Z

Right. Thanks.

roklenarcic 2021-05-31T13:44:53.191300Z

Is there some EDN reading library that has similar performance profile to JSON libraries? Or should I try to use Transit for storing basic Clojure datastructures to text?

Nom Nom Mousse 2021-05-31T13:46:26.192200Z

What would be a good way of getting elements 0 1 3 from each element of this list?

(def ls  '([73 62 15 3] [10 94 91 66] [44 24 4 23] [30 34 24 80] [46 58 60 56])))
This works, but I am wondering whether there are other ways:
(for [l ls] (vals (select-keys l [0 1 3])))

simongray 2021-06-01T10:32:38.244100Z

@endrebak (for [[a b _ d] ls] [a b d])

simongray 2021-06-01T10:32:48.244300Z

just use destructuring if you want it shorter

Nom Nom Mousse 2021-06-01T10:36:00.244700Z

That is a good suggestion! Since I am parsing java exceptions I think I can be sure each row has four elements.

vncz 2021-05-31T13:55:02.193Z

(defrecord Square [l])

(->Square 10)
(Square. 10)

vncz 2021-05-31T13:55:27.193700Z

Is there any meaningful difference between the two ways of constructing a record? Which one should I privilege? I know that the latter is Java interop (and we should stay away from it as much as possible) but other than that, is there a difference under the hood?

borkdude 2021-05-31T14:02:27.194900Z

Is there a reason this trailing metadata syntax should be supported in newer clojure dialects, other than compatibility?

(defn foo
  ([])
  ([_ _])
  {:x true})
vs metadata on the front:
(defn foo
  {:x true}
  ([])
  ([_ _]))

borkdude 2021-05-31T14:03:48.195500Z

clj-kondo also isn't able to deal with the first (currently) and nobody every complained about it so far, but I see it's being used in a library called omniconfig

danieroux 2021-05-31T14:07:11.196400Z

https://github.com/cognitect/transit-clj/commit/b2e4bc8c95a5c14c8cae5e9edf450d61461d89dc I would go with Transit as storage.

alexmiller 2021-05-31T14:57:50.197500Z

Compatibility seems like the main concern

alexmiller 2021-05-31T14:57:57.197900Z

It’s rarely used

alexmiller 2021-05-31T14:59:17.198800Z

You should definitely prefer the constructor function over interop

alexmiller 2021-05-31T15:00:22.200400Z

They do ultimately do the same thing but the constructor will be more portable and may have features the interop does not at some future point

vncz 2021-05-31T15:02:21.202800Z

@alexmiller Are you referring to anything specific regarding missing features? (This is out of curiosity)

alexmiller 2021-05-31T15:02:41.203600Z

juxt is a good thing to consider for “get multiple things from the same data”. It’s certainly not going to be shorter than what you have here though

alexmiller 2021-05-31T15:04:24.205800Z

edn is generally going to be much slower to parse than transit. If you want data for people to read/edit edn is better. If your concern is sending data or reading/writing data between programs, transit is better/faster

alexmiller 2021-05-31T15:05:20.206100Z

No

alexmiller 2021-05-31T15:05:53.207Z

But if I imagine where I’d put features as a language implementor, that’s one place

👍 1
Nom Nom Mousse 2021-05-31T15:07:22.207200Z

Thanks 🙂 But numbers cannot be used with juxt, right?

((juxt 0 1 3) "abcdefg") ;; error

p-himik 2021-05-31T15:31:25.207500Z

Each index should be wrapped in #(nth % index).

👍 1
indy 2021-05-31T15:50:28.207800Z

Just out of curiosity, did you search for this by using a regex with http://grep.app?

borkdude 2021-05-31T15:51:53.208Z

I did not

indy 2021-05-31T15:53:20.208200Z

Mind sharing how you found that the library uses metadata that way? 🙂 Just want to hone my searching skills too

borkdude 2021-05-31T15:54:00.208400Z

someone tried to use it with #babashka and bb didn't support that syntax yet

borkdude 2021-05-31T15:54:19.208600Z

If you want to search code using clojure.spec regexes, you can use: https://github.com/borkdude/grasp

❤️ 1
indy 2021-05-31T15:55:30.209Z

Sweet, I do know about this lib from one of the clojure podcasts ✌️:skin-tone-4:

Nicolas Estrada 2021-05-31T16:21:18.209300Z

I say print compiler warnings for next release, then kill it... 😅

alexmiller 2021-05-31T16:36:16.209600Z

Never

❤️ 2
alexmiller 2021-05-31T16:36:38.210200Z

There is no reason to break people for no reason

alexmiller 2021-05-31T16:37:23.210700Z

Like I said, it’s not shorter :)

sandeep 2021-05-31T16:49:46.213300Z

what would be the bestway to handle maps(google maps/ mapbox) in clojure -> integrate it in js or handle it with clojure

kwladyka 2021-05-31T16:57:14.215700Z

Can someone share article / thoughts about reasons of consistent google trends Clojure dropping? It can be subjective, but I also see less traffic on slack, than a few years ago. What is happening? Do (Don’t) developers have fun using Clojure or only developers which should stay with Clojure? What changed in September 2020 Clojure trends drop so much? Pandemic? How?

Nom Nom Mousse 2021-06-01T08:19:19.234400Z

I guess Lisps are always going to be something for the initiated. It would be interesting to see Clojure compared to other Lisps in such a graph.

Christoffer Ekeroth 2021-06-01T09:02:26.238200Z

@endrebak

😎 1
Christoffer Ekeroth 2021-06-01T09:02:39.238400Z

You can make your own at https://trends.google.com/

magra 2021-06-01T09:45:55.239500Z

I still say "I google" but i do not use google anymore but alternative search engines. I also block analytics, third-party cookies etc. And all the (not)"googling" I do for clojure rarely includes the word clojure as a search term. When I go to clojure cheatsheet, clojure toolbox or clojureverse they open from my browsers history. Then libraries in clojure have names which don't give away what the do, so (not)"googling" for "fulcro" "luminus" "reagent" will rarely include the search term "clojure". Even "clj-pdf" or "clj-http" will not show up as the searchterm clojure.

magra 2021-06-01T09:49:15.239700Z

As an aside: The red-monk, or whatever, popularity of programming languages index only uses searches, I suspect google only, for "x programming language". Now, who would ever google "clojure programming language"? In real life you google "java" then find out the search was to wide and then try again googling "java programming language". With clojure you google "clojure" and you got it. No need to ever refine the search.

kwladyka 2021-06-01T16:31:11.253100Z

> (Also worth remembering is that if Google Trends is a valid quality metric we should all be coding in Java / JavaScript 😉) Not really. Java doped too. Bur Rust is going up.

kwladyka 2021-06-01T16:34:10.253300Z

BTW What do you use to block cookies? Do you block all of them in web browser or user adblocker?

Joel 2021-06-02T15:53:27.285Z

I thought I just saw Clojure as 45th most popular language, which is higher than I've seen it before. (TIOBE maybe?)

Nom Nom Mousse 2021-06-02T15:56:45.285300Z

I use the Brave browser. It prevents plenty of tracking by default. I think newer versions of Safari do too.

magra 2021-06-02T17:23:11.286900Z

uMatrix. It has something like a spreadsheet of all the connections a website requests and I tell it which ones are ok. Not everyones cup of tea ;-)

Ben Sless 2021-05-31T17:12:35.215800Z

This is just a guess but let's break it down by region:

Ben Sless 2021-05-31T17:13:10.216Z

Let's narrow down on China:

Ben Sless 2021-05-31T17:13:39.216200Z

Very sharp drop off. Can it possibly account for the largest part of it?

Ben Sless 2021-05-31T17:14:34.216400Z

Interest in Clojure in Finland seems pretty consistent (go metosin!)

kwladyka 2021-05-31T17:15:28.216600Z

good point

Ben Sless 2021-05-31T17:16:33.216800Z

Israel Most of the traffic is probably from Appsflyer and during the pandemic our management took a very very conservative fiscal strategy and almost froze hiring. New hires do lots of googling

Ben Sless 2021-05-31T17:17:19.217Z

I think that explains most of it

Ben Sless 2021-05-31T17:17:57.217200Z

Curious to know what changed in China

kwladyka 2021-05-31T17:22:43.217400Z

Do you know website with statistic how many developers use Clojure each year?

vncz 2021-05-31T17:24:45.217800Z

Makes sense. Thank you!

roklenarcic 2021-05-31T17:50:57.222Z

thank you

Ben Sless 2021-05-31T18:22:22.222200Z

No, but you could refer to the annual Clojure survey

Ben Sless 2021-05-31T18:22:39.222400Z

https://clojure.org/news/2021/01/14/clojure-2021-survey

alexmiller 2021-05-31T19:57:17.228300Z

I think people are not generally aware what a high percentage of traffic tracking is being blocked by browsers these days which makes me look skeptically at these numbers

👍 3
👀 1
alexmiller 2021-05-31T19:59:05.230Z

We recently found as much as 90% of traffic to Datomic sites was being blocked from tracking so things like Google analytics were fairly inaccurate

kwladyka 2021-05-31T20:22:57.230400Z

good point too

ghadi 2021-05-31T21:57:29.230700Z

That's catchier than Linus Torvalds's quote about this subject

Christoffer Ekeroth 2021-05-31T22:50:46.231200Z

My take is that Clojure has entered the “Plateau of productivity” phase of the hype cycle. I mean it’s been around for 14 years now so I think most of the novelty factor has worn off. (Although this doesn’t account for the sudden drop in Sept. 2020) (Also worth remembering is that if Google Trends is a valid quality metric we should all be coding in Java / JavaScript 😉)

Christoffer Ekeroth 2021-05-31T22:57:07.231400Z

Another thing is that mainstream adoption takes time; after the novelty factor has worn off you have to scale a way larger hill, which is to become a battle-tested language that’s regarded as “production-ready”. Erlang lingered in obscurity for about two decades before the rise of instant messaging created a demand for the same kind of throughput and robustness that was a solved problem in telecom. TBH I don’t think the world “at large” is ready for Clojure; Python has begun to overtake Java / .NET in just the last few years, so I think it’ll be a while before “the industry” is ready for functional programming

Christoffer Ekeroth 2021-05-31T23:02:02.231600Z

That said, I personally believe that Clojure is uniquely well-suited for what’s going to be standard application development in a few years, which is to move yet more towards data processing and enabling systems to talk to each other. Most of my work nowadays is just building APIs that string together other APIs. Strong type systems and OOP are not much help here, but “interactive” (e.g. REPL-driven) development, persistent data structures, easy serialization and schemas / data-driven systems sure are.

👍 2
alexmiller 2021-05-31T23:29:44.232700Z

Well you can put quotes around that and attribute it to rich