clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2021-03-20T00:01:21.249300Z

gn

emccue 2021-03-20T00:01:48.249500Z

hmmm - so the message passing part is something that akka solves no?

emccue 2021-03-20T00:02:21.249700Z

I'd agree that the ability to share memory is an issue, but you could just choose not to right?

emccue 2021-03-20T00:02:34.249900Z

or like, choose not to make use of that

seancorfield 2021-03-20T00:02:45.250100Z

Naming is hard. But functions like this are common in “util” libraries out there. I haven’t felt a need for them in core.

seancorfield 2021-03-20T00:04:05.250300Z

I’ve always just used reduce-kv for any transformation over a hash map. Well, since it was added to Clojure in 1.4 🙂

2021-03-20T00:08:25.250500Z

I feel I rarely need to apply the same transform to all values in a map. Generally my maps model compound types, so the keys are specifically to distinguish the kind of values. And so I rarely need to make the same value change to all of them. With reduce-kv I can switch on the key to apply the appropriate transformation to the value.

Darin Douglass 2021-03-20T00:26:56.252900Z

@didibus re Perl/Ruby heredocs: our Perl code at work, iirc, only has a few heredocs and I can’t think of any in our ruby codebase either

piyer 2021-03-20T07:19:33.255900Z

Is there a way to do lein install clj-http ? I am expecting lein to install the dep and update the project.clj file.

dpsutton 2021-03-20T07:25:11.257100Z

lein install is a task to install the current project into your local repository, not add deps into your current project. There might be a plugin that achieves what you want but i'm not familiar with it. And with the speed of lein, I'd probably prefer to just go grab things myself.

Ivan Fedorov 2021-03-20T07:29:47.258600Z

Gauging interest to a Google Calendar client – published a scribble with specs. https://github.com/spacegangster/gcal-clj

Ivan Fedorov 2021-03-20T07:35:26.258800Z

Probably not. But it’s a good intent. Clojure’s build/task system could use an upgrade – maybe a new client written on babashka.

borkdude 2021-03-20T09:01:07.259500Z

For lein there is https://github.com/johnwalker/lein-plz

2021-03-20T17:05:51.261600Z

Looks like this is coming sooner then I thought: https://openjdk.java.net/jeps/401 https://openjdk.java.net/jeps/402 These could be pretty impactful for Clojures performance and memory use I think.

👍 1
rossputin 2021-03-20T17:09:27.262900Z

Hi - latest version of Practicalli’s Clojure Deps.edn is giving me ‘Could not find artifact com.github.seancorfield:next.jdbc:jar:2.0.193 in central (https://repo1.maven.org/maven2/)’ on running clojure -X:project/jar - anyone else seen this?

robertfw 2021-03-20T17:11:55.263200Z

@rossajmcd Probably worth asking this in #practicalli

rossputin 2021-03-20T17:20:08.263400Z

thanks for the heads up - didn’t spot that 🙂

dharrigan 2021-03-20T17:21:28.263600Z

That's most definitely a typo

dharrigan 2021-03-20T17:21:37.263800Z

Latest is 1.1.646

dharrigan 2021-03-20T17:22:12.264Z

Yes

dharrigan 2021-03-20T17:22:19.264200Z

2.0.193 is for depstar

dharrigan 2021-03-20T17:22:22.264400Z

<https://github.com/seancorfield/depstar/releases>

thheller 2021-03-20T17:26:43.265100Z

what kind of a lie is this exception? anyone have a clue what this could be about?

NullPointerException Cannot invoke "java.lang.Character.charValue()" because "x" is null
        clojure.lang.RT.intCast (RT.java:1220)

thheller 2021-03-20T17:26:53.265400Z

"x" is clearly not null?

p-himik 2021-03-20T17:31:19.266500Z

I would read it as if x is the name of the variable that's supposed to contain a character. (.charValue x).

thheller 2021-03-20T17:32:38.266700Z

ah indeed

p-himik 2021-03-20T17:33:57.266900Z

But now I'm interested in how one would get the message that reads "Cannot invoke blah-blah". :) All I get is "Execution error (NullPointerException) at blah-blah".

thheller 2021-03-20T17:34:35.267100Z

(nth [1 2 3] nil)

p-himik 2021-03-20T17:35:39.267300Z

Nope, still same message. Probably some difference in REPL/JVM.

p-himik 2021-03-20T17:36:04.267500Z

user=&gt; (nth [1 2 3] nil)
Execution error (NullPointerException) at user/eval159 (REPL:1).
null

thheller 2021-03-20T17:36:46.267700Z

I get the error I posted. this is all from the REPL. might be jdk15?

p-himik 2021-03-20T17:37:32.267900Z

Perhaps, mine is 14.

dpsutton 2021-03-20T17:45:11.268100Z

yeah newer jdk's added better null pointer messages i believe

JL 2021-03-20T20:07:55.275600Z

Question for the guru's - I'm stuck on sort-by with nested data. I want to sort by :class then by :key alphabetically I've tried

sorted (sort-by :key #(&gt; %1 %2) data)]
sorted (sort-by (juxt :class :key) data)
With no luck input data is:
{0 {[Wizard :true-strike] {:key :true-strike, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard}, 
	[Wizard :acid-splash] {:key :acid-splash, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard}, 
	[Cleric :word-of-radiance] {:key :word-of-radiance, :ability :orcpub.dnd.e5.character/wis, :qualifier nil, :class Cleric}, 
	[Cleric :encode-thoughts-dimir-guild-] {:key :encode-thoughts-dimir-guild-, :ability :orcpub.dnd.e5.character/wis, :qualifier nil, :class Cleric}}, 
1 {[Cleric :sanctuary] {:class-key :cleric, :key :sanctuary, :class Cleric, :ability :orcpub.dnd.e5.character/wis},
   [Cleric :protection-from-evil-and-good] {:class-key :cleric, :key :protection-from-evil-and-good, :class Cleric, :ability :orcpub.dnd.e5.character/wis}, 
   [Wizard :absorb-elements] {:key :absorb-elements, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard}, 
   [Wizard :unseen-servant] {:key :unseen-servant, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard}, 
   [Cleric :cure-wounds] {:class-key :cleric, :key :cure-wounds, :class Cleric, :ability :orcpub.dnd.e5.character/wis}, 
Desired output is:
{0 { [Cleric :encode-thoughts-dimir-guild-] {:key :encode-thoughts-dimir-guild-, :ability :orcpub.dnd.e5.character/wis, :qualifier nil, :class Cleric}}, 
     [Cleric :word-of-radiance] {:key :word-of-radiance, :ability :orcpub.dnd.e5.character/wis, :qualifier nil, :class Cleric}, 
     [Wizard :acid-splash] {:key :acid-splash, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard}, 
     [Wizard :true-strike] {:key :true-strike, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard}, 

1 { [Cleric :cure-wounds] {:class-key :cleric, :key :cure-wounds, :class Cleric, :ability :orcpub.dnd.e5.character/wis}, 
    [Cleric :protection-from-evil-and-good] {:class-key :cleric, :key :protection-from-evil-and-good, :class Cleric, :ability :orcpub.dnd.e5.character/wis}, 
    [Cleric :sanctuary] {:class-key :cleric, :key :sanctuary, :class Cleric, :ability :orcpub.dnd.e5.character/wis},
    [Wizard :absorb-elements] {:key :absorb-elements, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard}, 
    [Wizard :unseen-servant] {:key :unseen-servant, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard}, 

p-himik 2021-03-20T20:36:45.278500Z

Your second attempt looks fine to me. But it acts on separate values of that map - just apply it to them in reduce-kv or into with a transducer.

p-himik 2021-03-20T20:38:08.278700Z

Oh, wait - I'm wrong. Your values are also maps. So you want a sorted-map-by, not sort-by.

p-himik 2021-03-20T20:41:04.278900Z

(into {}
      (map (fn [[id datum]]
             [id (into (sorted-map) datum)]))
      data)

➕ 1
pavlosmelissinos 2021-03-20T20:54:49.279200Z

Besides what @p-himik said, the data looks really weird to me. Does it have to be so nested? Wouldn't something like this be much more simple and clean?

{0 [{:key :true-strike, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard},
    {:key :acid-splash, :ability :orcpub.dnd.e5.character/int, :qualifier nil, :class Wizard},
	...],
 1 [{:class-key :cleric, :key :sanctuary, :class Cleric, :ability :orcpub.dnd.e5.character/wis},
    {:class-key :cleric, :key :protection-from-evil-and-good, :class Cleric, :ability :orcpub.dnd.e5.character/wis},
    ...]}

p-himik 2021-03-20T20:57:00.279600Z

Indeed. I would also add that if you only need to index via consecutive natural numbers then it might be better to use a vector. Vectors are associative and their keys are natural numbers - indices of the elements:

=&gt; (assoc [1 2] 1 3)
[1 3]

➕ 1
JL 2021-03-20T21:01:28.280Z

@pavlos it is what is being processed (inherited) I'll give

(into {}
      (map (fn [[id datum]]
             [id (into (sorted-map) datum)]))
      data)
A shot

👍 1
JL 2021-03-20T21:07:45.280200Z

@p-himik Thanks! That appears to do the trick : ]

👍 1
practicalli-john 2021-03-20T22:39:33.280800Z

Sorry, I copy-pasted next.jdbc instead of depstar into the alias... and its not even April 1st. Sorry for the mistake. Its been fixed and pushed to GitHub Also suppressed the logging warning for :project/outdated And a few more library verison updates.

seancorfield 2021-03-20T22:48:48.281Z

My dot-clojure file has a :j14 alias that enables a JVM option that produces the more verbose exceptions.

seancorfield 2021-03-20T22:51:16.281400Z

{:jvm-opts ["-XX:+ShowCodeDetailsInExceptionMessages"]}

seancorfield 2021-03-20T22:51:30.281600Z

It was new in JDK 14.