Fork me on GitHub
#clojure
<
2019-04-05
>
tomjkidd02:04:36

Trying to use lein kibit with a dependency that uses .cljc files, getting No namespace: foo.bar.baz found as an error. Does anyone know how to resolve this?

tomjkidd14:04:04

Turns out, this is because I was using #foo.bar.baz{:a 1}, and I don’t think the reader knows how to handle it.

tomjkidd14:04:20

Fix was to use {:foo.bar.baz/a 1} instead

tomjkidd02:04:10

I am tracing it back, kibit uses org.clojure/tools.reader, and [clojure.tools.reader$read_namespaced_map invokeStatic "reader.clj" 760] is where it is crashing, but I’m not very familiar with this reader lib.

tomjkidd02:04:22

I am tracing it back, kibit uses org.clojure/tools.reader, and [clojure.tools.reader$read_namespaced_map invokeStatic "reader.clj" 760] is where it is crashing, but I’m not very familiar with this reader lib, and it is not clear to me that cljc support is provided…

mike_ananev04:04:58

javapackager distro for JDK 11

deep-symmetry03:04:04

Interesting! And it looks like they are making good progress on the one they are going to release officially. Until then I am getting by fine using my JDK 8 javapackager pointed at a current OpenJDK distro to build my Mac app, and one of my kind Windows users has set up an sftp server that uses a third-party tool to create a nice MSI installer.

jumar06:04:46

I've just run jcmd <pid> in a docker container running our Clojure application on OpenJDK 11 (Ubuntu). In the "Internal exceptions" section I've found a few instances of this exception:

Event: 4103.838 Thread 0x00007f800400c800 Exception <a 'java/lang/ClassCastException'{0x00000000c78ba0b0}: class clojure.lang.Keyword cannot be cast to class java.lang.CharSequence (clojure.lang.Keyword is in unnamed module of loader 'app'; java.lang.CharSequence is in module java.base of loader
I couldn't find any info about this one (or what exactly the "Internal exceptions" mean in this context) so I'm wondering if it's something I should worry about.

noisesmith16:04:28

this means that some code is trying to do string operations on keywords (maybe you already know this)

noisesmith16:04:57

from your stack overflow thread: > I suppose, neither your application nor the JDK code would ever deal with a clojure.lang.Keyword this is wrong, of course, we use keywords all the time

Nazral08:04:02

I've just encountered a strange bug: labels-probs (sort-by :score >= (map #(do {:score %2 :label %1}) labels clean-probs)) This was crashing for one of my inputs (`clean-probs` is a list of double) with a comparison not respecting contract error. Yet I checked the data, all the elements of the list are valid floats (just, some extremely small, goes to E-39 iirc). So I figured I might as well do (map #(if (< % 0.001) 0 %) to clean-probs and it worked, it doesn't crash anymore

Nazral08:04:05

But I don't understand why >= was crashing and not <.

dominicm09:04:10

@archibald.pontier_clo your stack trace would probably be useful 🙂

Nazral09:04:31

ok I'll get it (it's not accessible anymore, but I can rollback to a commit that had this problem)

restenb10:04:05

i've got a list of tables, and would like to "merge" them in a way such that the new table orders them by element order, i.e

restenb10:04:43

Table merging

restenb10:04:14

so my three 3x2 tables turn into one 9x2 merged by element. racking my brain on how to do this

yuhan10:04:18

your example shows a 9×2 result table, not 3×6?

restenb10:04:07

oh yeah, i changed the result. it should be 9x2 like it is now

restenb10:04:40

so merging the nth vector in each table together in a new vector

yuhan10:04:33

(apply map concat list-of-tables) should do it

yuhan10:04:11

the multi-arity versions of map and mapcat can come in useful in these situations

restenb10:04:33

aaaah, damn. that's nice 🙂

djtango11:04:35

does anyone know why this might behave differently in prod (heroku) to local dev?

(defn fn-name
  [f]
  (as-> (str f) $
    (clojure.main/demunge $)
    (or (re-find #"(.+)--\[email protected]" $)
        (re-find #"(.+)@" $))
    (last $)))

djtango11:04:04

(am using it to publish the name of a routing handler in monitoring)

djtango11:04:38

locally it correctly knows the function name but in prod it seems to produce :

jumpnbrownweasel15:04:17

Since it seems to be a pure function, it must be getting a different input param in production. I suggest printing the input param in production, and then you can use that value to reproduce it locally and debug it.

eraserhd17:04:59

Is there a function available somewhere to abbreviate namespace/package names? e.g. net.eraserhead.foo.bar -> n.e.foo.bar?

noisesmith17:04:14

@eraserhd what's the use case for abbreviating? require with :as allows that for clojure namespaces, but there's no equivalent for java packages

noisesmith17:04:35

(require '[clojure.string :as c.s])

eraserhd17:04:15

This is for logging. I have fully qualified symbols for rule names, and I'm logging a table of fire counts. With the full namespace, it pushes the counts off the screen.

eraserhd17:04:48

I've seen it in logging excpetions before... I guess it wasn't in the new pretty errors, huh?

noisesmith18:04:55

@eraserhd I know there are libraries that change default stack trace printing, and I'm sure each logging library has some way to alter how it prints packages

the2bears19:04:33

@eraserhd that's default type behavior with logback setups. We have that here.

aryyya19:04:07

I’m having a bit of trouble understanding why this code continues to realize the sequence: https://pastebin.com/raw/XSsdrLqS You can see a REPL session and clarifying question at the bottom.

lilactown19:04:12

(filter vampire?
           (map get-details ids))
filter forces the first lazy seq created by map to be realized

lilactown19:04:41

IIRC how it works

lilactown19:04:52

you'll need to use transducers if you want to chain them without realizing the whole seq

aryyya19:04:38

Ok, I do not know what a transducer is at this point.

lilactown19:04:19

transducers are a way of composing operations on lazy sequences like map filter etc.

aryyya19:04:12

@manutter51 Ah ok I think I see some chunking happening. Because if I give a very large range it only seems to realize the first 32 elements.

hipster coder20:04:23

check this out… I wrote the Fibonacci Sequence in 3 different langs…

hipster coder20:04:52

feel free to comment on the github and improve it

tyler21:04:06

Are there any good clojure.tools.deps parallel test runners out there? Can’t seem to find any with a google search.

dominicm05:04:22

I'm using eftest

dominicm05:04:54

Libraries don't need to explicitly support tools.deps, they just need to be a clojure library

tyler05:04:07

This is great. Thank you.

tyler22:04:14

Thanks! I’d looked in there but neither of the options for clojure supported running tests in parallel unfortunately.

Nolan22:04:04

has anyone ever ran codox from the command line, or otherwise in the absence of boot or lein?

Dustin Getz23:04:53

How can I implement a protocol on a value (map with many keys) and retain the ability to update the map without losing the protocol?

noisesmith23:04:48

this is what defrecord is for

Dustin Getz23:04:48

The keys are namespaced, and optional, and numerous, the type of thing you would spec

Dustin Getz23:04:04

Or are you suggesting (defrecord [m] …)

noisesmith23:04:06

why would defrecord care about that?

noisesmith23:04:44

what I mean, is you use defrecord to define a new map type which extends the protocols / interfaces you are targetting

noisesmith23:04:09

it doesn't need to define any of those keys in its declaration - you are free to add any key you like

noisesmith23:04:13

user=> (defrecord Foo [x] Object (toString [this] (str "foo with x:" x)))
user.Foo
user=> (map->Foo {:x 42 :bar/y 4 :z 22})
#user.Foo{:x 42, :bar/y 4, :z 22}
user=> (str *1)
"foo with x:42"

(fixed to include a namespaced key)

Dustin Getz23:04:47

Thanks, you are right

Dustin Getz23:04:00

(assoc *1 ::bar 43) => #user.Foo{:x 42, :y 4, :z 22, :user/bar 43} I did not expect this to work