Fork me on GitHub

from the docstring of > Unlike cond and condp, case does a constant-time dispatch, the clauses are not considered sequentially. can someone explain in plain English what that means?


it jumps to the condition, rather than linearly checking the conditions one at a time

👍 5

it compiles to effectively (or maybe literally) a hash-map lookup on the dispatch value

Alex Miller (Clojure team)02:03:08

the jvm has two bytecodes supporting "switch" - one is a linear series of checks, the other is effectively a constant time jump table keyed off of hashcode

Alex Miller (Clojure team)02:03:24

Clojure's case does a ridiculous amount of work to use the latter

👍 20

That got me scrolling through my phone to find the case source, which stirred up a couple of questions/comments: 1.) some?, if-some, when-some— do people use these often? I don’t, personally. Anyone have insight as to why they made it into core? I think I saw an added in 1.6, which makes me guess at it being related to transducers? Maybe I’m off 0.2 and that was the time of reducers? Either way, curious on the history. 2.) mod’s docstring has a line “Truncates toward negative infinity.” Could someone explain that to me, and perhaps provide an example of why it’s important to know?


I typically avoid calling modulo/remainder or division operations on negative numbers, to avoid having to know, and because applications I have written didn't need such operations on negative numbers. But this page on the divide and modulo behavior in various flavors of C/C++ might answer some of your question:


I prefer if-some and when-some over if-let and when-let almost every time


if I remember correctly the reason why they were added was because core.async channels impose nil as the end-of-stream sentinel


> I prefer if-some and when-some over if-let and when-let almost every time yes I've met other clj programmers following that style It might boil down to Java-like vs. Lisp-like boolean semantics (in Java there's no 'truthiness' - just true and false can be used in conditions). Some people prefer Java-like


Hi! Anybody knows of a clojure nlp library with things like RAKE/LDA?


Thank you! I actually know about corenlp but it doesn't have LDA nor RAKE. I know Spark has LDA but I'd like to avoid to massive overhead Spark creates... Worst case I'll go an implement it...


I saw something about LDA mentioned in the JavaDoc of CoreNLP, that’s why I thought it may be relevant, but maybe not.


I'm trying to find any previous implementations (or some library I could steal ideas from) for having a pipeline which basically all functions inside this pipeline depends on the previous step and also have side-effects. Goes something like fetch source -> build -> report status but with a bit more steps in-between. Any previous art or thoughts on the subject are welcome! I've looked at some implementations using async/pipeline but feels like over-engineering for my case, no need for it to be async

Scott McCaughie14:03:21

If I understand your requirement, I’ve done similar before simply using thread-first, passing a context as I go:

(-> initial-context fetch-data parse-data categorise send)


Ah, basically build up some context map that contains all the parts that are needed? Actually not a bad idea

Scott McCaughie14:03:34

Yep exactly. You’re welcome 🙂


I couldn’t find channel, so asking here: At the time of table creation, if I provide [:age :int :default 18] then jdbc throws error, but it accepts "18", which is logically incorrect. How to handle this?


the channel for jdbc is #sql


oh okay, thanks


I'm making myself crazy with this... I'm using to create a json string. The string I want to create looks like this: {"query": {"field": {"text": "123",


Sorry, hit the wrong key. Let me try again.


{"query": {"field": {"text": "123", "title": "ABC"} } }


the json/write-str I use looks like this: (json/write-str {:query {:field {:text "123", :title "ABC}}})


But I keep getting "No value for key" error on the generation.


I've tried just about every combination I can think of, with no joy.


is the " after C missing in your original?


Does someone see something I'm missing?


No, it's there. Just a typo.


user=> ((fn [& {:as m}]) 1)
Execution error (IllegalArgumentException) at user$eval1467$fn__1469/doInvoke (REPL:1).
No value supplied for key: 1

noisesmith20:03:10> (j/write-str {:query {:text "123", :title "ABC"}})
"{\"query\":{\"text\":\"123\",\"title\":\"ABC\"}}"> (println *1)
nil> (j/write-str {:query {:text "123", :title "ABC"}} :foo)
IllegalArgumentException No value supplied for key: :foo  clojure.lang.PersistentHashMap.create (


extra arg, yeah


It seems to me that query is matched by field, field is matched by the object containing text and title. Everything has a key value. The original JSON validates. It just doesn't work with json/write-str. Very odd.


you are providing the wrong number of args to write-str


what does the stacktrace say?


Where did the :foo come from in your example?


it's how you make that error message happen


Ah. Is there a better way to make sub-objects in a JSON string with json/write-str?


what does this mean?


you have supplied the error message, which says what the error is, but the stacktrace will tell you where the error is actually happening


IllegalArgumentException no value supplied for key: then: clojure.lang.PersistentArrayMap.createAsIfByAssoc (


*e will contain the full trace


That's the whole stack trace (this is in the repl)


that's not a stack trace, it's a message


*e contains the trace


Never mind, I see it.


Here's the whole thing: at [clojure.lang.PersistentArrayMap createAsIfByAssoc "" 79]}] :trace [[clojure.lang.PersistentArrayMap createAsIfByAssoc "" 79] [clojure.core$array_map invokeStatic "core.clj" 4256] [clojure.core$array_map doInvoke "core.clj" 4249] [clojure.lang.RestFn applyTo "" 137] [clojure.core$apply invokeStatic "core.clj" 646] [clojure.core$apply invoke "core.clj" 641] [clojurewerkz.elastisch.arguments$GT_opts invokeStatic "arguments.clj" 9] [clojurewerkz.elastisch.arguments$GT_opts invoke "arguments.clj" 3] [$register_query invokeStatic "percolation.clj" 30] [$register_query doInvoke "percolation.clj" 25] [clojure.lang.RestFn invoke "" 467] [esearch.handler$get_register_search invokeStatic "handler.clj" 124] [esearch.handler$get_register_search invoke "handler.clj" 119] [mysql.core$eval11790 invokeStatic "form-init1224899402989498950.clj" 1] [mysql.core$eval11790 invoke "form-init1224899402989498950.clj" 1] [clojure.lang.Compiler eval "" 6927] [clojure.lang.Compiler eval "" 6890] [clojure.core$eval invokeStatic "core.clj" 3105] [clojure.core$eval invoke "core.clj" 3101] [clojure.main$repl$read_eval_print__7408$fn__7411 invoke "main.clj" 240] [clojure.main$repl$read_eval_print__7408 invoke "main.clj" 240] [clojure.main$repl$fn__7417 invoke "main.clj" 258] [clojure.main$repl invokeStatic "main.clj" 258] [clojure.main$repl doInvoke "main.clj" 174] [clojure.lang.RestFn invoke "" 1523] [nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 79] [nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 55] [nrepl.middleware.interruptible_eval$interruptible_eval$fn__764$fn__768 invoke "interruptible_eval.clj" 142] [clojure.lang.AFn run "" 22] [nrepl.middleware.session$session_exec$main_loop__865$fn__867 invoke "session.clj" 171] [nrepl.middleware.session$session_exec$main_loop__865 invoke "session.clj" 170] [clojure.lang.AFn run "" 22] [java.lang.Thread run "" 748]]}


esearch.handler is my code.


so this problem has nothing to do with data.json


Probably not, but I presume that people have built JSON like this before with data.json..


I'm just looking for what I'm doing wrong in my write-str.


write-str has nothing to do with that error


write-str triggers it, that's all I know.


if that were true, write-str would be in the stack trace


I'd think so. It could be when it gets passed to ElasticSearch. Maybe something goes wrong there.


what does ->opts do and how is it being called?


You are most likely realizing a lazy sequence that was created somewhere else.


I think one problem might be that the values for title and text aren't simple like "123". They are 1024 character strings containing search terms that may or may not have foreign characters in them.


And the error is in what you passed to the code that created that lazy sequence.


That's a reasonable idea.


Is -Dclojure.compile.warn-on-reflection property supposed to work? If so, what effect should it have? I supposed it will set the reflection warning dynvar for all namespaces by default, but it doesn't seem to.


-Dclojure.compile.warn-on-reflection=true should work.


$ clj -J-Dclojure.compile.warn-on-reflection=true
Clojure 1.10.0
(cmd)user=> *warn-on-reflection*


I think it only sets it when compiling


Ah, yes, that's it.


So its not controlling the value of *warn-on-reflection*, it is just looked up as well by the compiler when compiling to decide if it should emit or not the warnings.


@U0K064KQV So it seems like I can't use it to check all namespaces for warnings. Sad.


clojure -J-Dclojure.compile.warn-on-reflection=true -e "(compile 'entry.point)" should do it @U06PNK4HG?


(you'll need a classes folder for it to compile into -- or else add a binding call around the compile for *compile-path*)


I still use Boot, but thanks, I will try to do something similar.


@nkraft have you shown us exactly what code is on line 124 of esearch.handler?


this is Elastisch, submitting a query to the ElasticSearch percolator: (pcl/register-query conn index rowid json) That's on line 124. 'json' is the output of data.json. index and rowid are strings.


Which version of Elastisch are you using? The stack trace does not match the latest version.


It looks to me like register-query expects kw-args style arguments, i.e., named arguments, not a single JSON map.


Elastisch is 2.2.1


Really, I didn't see that in the docs. That is very helpful to know.


Yes. Then you're calling it per the 3.x API, instead of the 2.x API.


& args is expected to be unrolled keyword args, not a map.


In Elastisch 3.x, this call changed to accept a single hash map of opts


So you either need to change your call or update to 3.x.


I'll try both. 🙂


Well, updating Elastisch to 3.0.0 didn't fix it. Same problem. I'll try keyword args rather than the JSON.


It should be a hash map not a JSON string.


Here's the commit that changed the kwargs to option hash maps across the whole of Elastisch in May 2016


So (pcl/register-query conn index rowid {:query {:text "123" :title "ABC"}}) for 3.x or (pcl/register-query conn index rowid :query {:text "123" :title "ABC"}) for 2.x.


Thanks that's very helpful. OF course our ElasticSearch servers just went down so I'll have to test later. My localhost ES doesn't have enough data for what I'm doing.


[ANN] Cognitect Labs' aws-api 0.8.273 is now available:!topic/clojure/PgnJxiam_qk


this is pure gush but i just got my first full-time clojure gig and am incredibly excited. thanks for being such a thoughtful, curious community lambdalove

🚀 40
🎉 35

Nice, congratulations!


@seancorfield I have to thank you. That one post about 3.x vs. 2.x was the key. It's fixed now.


@bbqbaron Congratulations! That's pretty exciting.

👍 5

@nkraft This is a good example of why Rich is such a strong advocate of accretion, relaxation, and fixation -- rather than breakage. Admittedly, Elastisch did a major version change to signal "potential breakage" per so-called Semantic Versioning, but it really does show that you never really know whether updating to a new major version is "safe" or not -- and changes like this make it hard to trust the docs, unless they are also fully versioned for every new release.


(That said, my "flagship" Clojure project, also went through two rounds of API breakage -- to move to a more idiomatic API -- and, in fact, it was precisely the same changes that Elastisch made, switching from keyword arguments to an options hash map!)


That's true. I use your java.jdbc as well. Many times reading code is all that really works. Still, in my job I'm often trying to hack together something needed in a matter of hours, and I rely on docs to get things started probably more often than I should.


(I write mostly back end data moving stuff)


I don't think I've broken the java.jdbc API in about two and a half years now, but 2016 and 2013 were bumpy years for the API 🙂


(unfortunately there are still a lot of books and tutorials out there containing 0.2.x examples which haven't worked since 2013 😞 )


I saw the following spec in some code and I was wondering what the or was supposed to do.

(s/def ::my-string string?)
(s/def ::my-int integer?)
(s/def ::my-spec (s/keys :req-un [(or ::my-string ::my-int)]))
I generated a few samples using clojure.spec.gen.alpha/generate and saw that it does not yield the same results in Clojure 1.9 and 1.10. In 1.9, it always returns maps with both keys (which looks like a bug :thinking_face:) In 1.10, it returns maps with either ::my-string key, ::my-int or both (which looks like a normal or) What is the expected behavior?

Alex Miller (Clojure team)22:03:00

well first, the or here is not xor, so the generated examples in 1.9 are still "correct". in 1.10, it was updated to include either or potentially both.

Alex Miller (Clojure team)22:03:41

so, expected behavior is its current behavior


Great, thanks for your answer


It seems like the valid? function behaves the same way on this spec, though


So in 1.9, it generates only one case (both keys) of the 3 valid ones (first key, second key, both keys)

Alex Miller (Clojure team)22:03:43

yes, we improved it

👍 5

@seancorfield I recently learned about clojure.jdbc. Are you aware of it and its criticisms of java.jdbc?


Are you aware that it started life by copying code from and ripping out the license and copyright? I had to call the guy out on the main Clojure Google Group for that.

😬 5

FWIW I still use java.jdbc but I thought it might be worth sharing


I find it odd and annoying that the clojure.jdbc docs call java.jdbc, and that the project picked a name such that many discussions about using jdbc with clojure now look ambiguous


I haven't used it at all though


yeah, we can refer to it as funcool jdbc 😉


Are you aware that it started life by copying code from and ripping out the license and copyright? I had to call the guy out on the main Clojure Google Group for that.

😬 5

Also, it's criticisms are mostly out of date (and will be completely irrelevant when next.jdbc comes out which I've been working on a for a while). And it hasn't had any code updates in three years now (and only minor doc updates that were two years ago) -- so I'd say it's abandoned at this point.


great, thanks. So yes, you were aware, now I know 😉


didn’t know there was this “drama” associated with it. I just saw someone mentioning it on clojureverse


Somewhere he said: > Currently I have removed all taken code from the, license problem should be solved. I wonder with what he replaced that code then


I won't comment on that... for legal reasons...


fine, we can close this topic


Where it was mentioned on ClojureVerse, I also pointed out that the original code was ripped off, BTW. Or is there another thread that mentions it?


I’ll see if I can find this


(that's the only thread that search finds where it seems to be mentioned)

Lennart Buit22:03:32

thats so uncool, not attributing code. Even disregarding the legal implications

Lennart Buit22:03:07

derivation is at the heart of open source, but not by copying others work and posing it as your own


or maybe it was on Reddit… or Zulip… or Slack… I forgot, sorry 😕


I think I saw a mention on Reddit (and also linked to the Google Group thread there about the code being ripped off in the early versions).


This was the comment: and I see 3 days later you reacted on it. I think I missed that.


I try to catch every mention of it I can. As someone who's been doing OSS development for over twenty five years, I'm very sensitive to the issues of licensing and plagiarization 😠

©️ 25

Rightly so. Sorry man, didn’t want to trigger you into a bad mood.


We're good. I'm just listening to Amanda Palmer's new album so not much is going to dampen my enthusiasm today 🙂


legal issues aside, it's a disrespectful way to engage with a project whose work is leveraged that heavily


that’s totally (f)uncool

😏 5

(sorry, bad joke 😉 )


this went from technical to legal issues ( but the technical part was never talked about )

Lennart Buit22:03:15

or ethical 😛


As technical people, we'd do well to remember there are ethical and legal aspects to our work a lot of the time... for example

Lennart Buit23:03:19

I often cite ‘computer ethics’ as the most influential course in my masters

✔️ 5

which uni? my uni also paid quite some attention to it

Lennart Buit23:03:34

University of Twente (Enschede, The Netherlands)


Yep, that’s where I was too 🙂

Lennart Buit23:03:31

Also had lectures from Johnny Søraker? Its such a shame that he’s no longer at the uni…


I graduated in 2005


Don’t know the name.

Lennart Buit23:03:20

yeah probably not, I think he started teaching around 2006. Anyhow, cool to hear that this has been a trait of the UT for so long. I still believe that having a good ethics course is great for a computer scientist.


Small world 🙂

Lennart Buit23:03:40

Quite, moreso because the university we went to is one of the smaller of The Netherlands