clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
seancorfield 2021-04-18T00:44:08.207300Z

@nbtheduke it’s clj -X:new so it’s 🅱️

👍 2
seancorfield 2021-04-18T01:01:38.208300Z

@jayzawrotny Interesting that, so far, it’s a 50/50 split between “other” and A+B.

2021-04-18T22:30:08.237800Z

Wasn’t expecting that! Wanted to know how to best update https://github.com/eccentric-j/cljs-tui-template. Sounds like the path forward is to support clj-new and generate a blank version into a separate repo people who use neither can reference.

seancorfield 2021-04-18T23:07:48.238200Z

I think quite a few people take the approach of "clone a similar project and then hack it into what I want" which isn't really how OSS projects are intended to be used but... ¯\(ツ)

seancorfield 2021-04-18T23:08:48.238400Z

Are you aware of the changes both clj-new and lein new have made recently to better support the Clojars VGNs policy?

2021-04-19T00:41:38.238900Z

Oh good, I wasn't aware those libraries made any changes. I'll read up on that. Thanks for the heads up.

seancorfield 2021-04-19T01:41:37.239500Z

LMK if you have any Qs -- I drafted them first for clj-new and then worked with Phil on Leiningen's changes.

2021-04-19T01:47:13.239700Z

Thank you, will probably start focusing on that one I switch blessed + react-blessed -> ink 3.

2021-04-19T01:48:26.239900Z

btw working on it live at https://gather.town/i/kcWbjU1O for another hour or so. Password is enclojure if you or anyone wishes to see progress or chat.

macrobartfast 2021-04-18T01:57:31.212100Z

When I call function A with function B inside it, function B doesn’t evaluate. When I evaluate function B outside function A with cider, it evaluates. Thoughts?

macrobartfast 2021-04-18T01:58:40.213200Z

I’m wondering if it’s a lazy evaluation thing, as function B has a map in it; but trying doall and dorun doesn’t help.

seancorfield 2021-04-18T02:02:35.213700Z

@macrobartfast Guess we’d have to see the code?

macrobartfast 2021-04-18T02:03:12.214600Z

haha definitely… I’m trying to isolate/reproduce it as it’s a huge bloated not-my-code mess I can’t post here…

macrobartfast 2021-04-18T02:03:24.214900Z

I’ll see if I can do that, though.

macrobartfast 2021-04-18T02:03:44.215400Z

I was just praying you were psychic, is all.

seancorfield 2021-04-18T02:04:54.216900Z

You would at least need to provide a bit more precision around terms like “doesn’t evaluate” etc, and explain how you reached the conclusions about what is and what is not happening, i.e., what you tried, what behavior you got, what behavior you expected.

seancorfield 2021-04-18T02:05:35.217300Z

Debugging should be a scientific endeavor, after all…

macrobartfast 2021-04-18T02:06:28.217500Z

science?

macrobartfast 2021-04-18T02:06:46.217900Z

no, totally fair enough… I’ll do my homework.

yuhan 2021-04-18T05:05:43.220400Z

Are there any downsides to using a library like https://github.com/bsless/clj-fast to unroll core functions for performance? It seems like almost a no-brainer to me to get some extra performance for free.

Ben Sless 2021-04-18T09:18:38.222900Z

It depends on a few things. First, the JIT needs some time to warm up. Secondly, there's only so much the JIT can do whenever iteration is involved. If you do lots of "get-in" you can't JIT away the iteration unless it's a pretty simple case, usually involving numerical computation

Ben Sless 2021-04-18T12:40:11.225800Z

btw, I'm very curious about you you checked this

yuhan 2021-04-19T01:08:48.239100Z

I actually wrote a small macro which uses clojure.walk to replace any function-head invocations with the inlned macros, then used it to wrap a few high-churn functions (according to the flame graph profiler)

(defmacro inline
  "Rewrites clojure.core fns in head positions
  to their inlined macro versions"
  [form]
  (let [mapping {'get       `inline/get
                 'get-in    `inline/get-in
                 'assoc     `inline/assoc
                 'dissoc    `inline/dissoc
                 'assoc-in  `inline/assoc-in
                 'dissoc-in `inline/dissoc-in
                 'update-in `inline/update-in
                 'merge     `inline/merge}]
    (walk/postwalk
      (fn [x]
        ;; Only replace if it's in function head position
        (if (seq? x)
          (if-let [[head & tail] (seq x)]
            (if (contains? mapping head)
              (cons (mapping head) tail)
              x)
            x)
          x))
      form)))

yuhan 2021-04-19T01:12:29.239300Z

Total execution time went from about 7 seconds down to 5, I didn't use Criterium to measure rigorously but it was on a long-running REPL with I assume the JIT being fully warmed up.

Ben Sless 2021-04-19T06:03:50.240400Z

Interesting. Thank you. Is that a one-off program? I'd be interested in seeing the run-time for a 100 executions before/after inlining, if you find time

Ben Sless 2021-04-18T06:03:10.220800Z

As the author (hi 🙂 ), I can think of a few: • bugs. You trust me and my library instead of clojure.core which is better tested and has many more eyes looking at it • load time. If you don't AOT compile your code namespaces will take longer to load and an application will be slower to start • API drift. If the API of any function or macro I implemented changes, I have to keep track of it, otherwise the implementation will become incompatible with time.

yuhan 2021-04-18T06:32:01.221Z

Hi and thanks for the reply 😄 I'm least worried about the last point given how famously stable Clojure's API has been over the years, and I see how macroexpansions can hurt load times although it's not a concern in my case. Hopefully this library gets more users / contributors to iron out any bugs!

Ben Sless 2021-04-18T06:36:28.221200Z

I also copied tests from Clojure's core which helped me catch a few edge cases

yuhan 2021-04-18T06:36:48.221400Z

I tried applying it to a portion of my code which deals with lots of nested maps, and immediately got a 35% speedup out of nowhere 😮 Always assumed that the JIT was optimizing away things like this in the background, but apparently simple macroexpansion-time analyses like this can have such a big effect

😮 1
grounded_sage 2021-04-18T08:26:37.222500Z

Is there a tool for getting a diff of two large CSV’s?

pavlosmelissinos 2021-04-18T08:45:49.222600Z

define "large" 😛 There's https://clojuredocs.org/clojure.data/diff Not sure if directly calling git diff --no-index a.csv b.csv would be faster/lighter

rakyi 2021-04-18T12:08:18.223500Z

there is https://linux.die.net/man/1/comm but the files must be sorted

rakyi 2021-04-18T12:10:10.223900Z

and of course the general diff

grounded_sage 2021-04-18T12:39:53.225600Z

Probably a few million rows. But I’m thinking of a solution which could handle large datasets. Perhaps tech.ml.dataset is the solution. Bit of a sledgehammer though

wombawomba 2021-04-18T13:27:03.230400Z

So I have a weird problem where Leiningen checkouts have stopped working since I made some of my (checked out) libraries .cljc instead of .clj. Basically, requiring some.lib-ns from some.other-lib-ns fails when some.lib-ns is in a .cljc file and is part of a library symlinked to checkouts in my project. However, I can still require that ns from a REPL just fine (i.e. (require 'some.lib-ns) works). Any idea what's going on here? Is there anything I can do about it?

wombawomba 2021-04-18T13:27:57.230500Z

FWIW the error I get is

java.lang.Exception: namespace 'some.lib-ns' not found
clojure.lang.Compiler$CompilerException: Syntax error compiling at (some/other_lib_ns.clj:1:1).

2021-04-18T16:45:02.234500Z

Might be a problem with your indexes. Have you tried File -> Invalidate Caches / Restart... ?

vemv 2021-04-18T18:44:48.234800Z

I don't think .cljc makes a difference at all lein checkouts basically places an entry into the classpath. You can debug it with e.g. lein classpath, or ps aux | grep java which will show your clojure process + its classpath

vemv 2021-04-18T18:45:22.235Z

if the desired folder is in the classpath, that allows you to rule out some things

2021-04-18T19:21:25.235300Z

FYI: The work to require verified group names on Clojars has been released. See https://groups.google.com/g/clojure/c/cWG-V_4uv90/m/EDx0Fqn_AgAJ for more details.

👍 2
2