Fork me on GitHub
#clojure
<
2019-10-03
>
cddr10:10:58

I'm running into a problem where an implementation of a method that I expect to be found is not being found....

No implementation of method: :clj->avro of protocol:
   #'jackdaw.serdes.avro/SchemaCoercion found for class:
   jackdaw.serdes.avro.StringType
I expect the code below to provide that method but even when I evaluate it immediately before running a test that requires it, I run into the error above.
(defrecord StringType []
  SchemaCoercion
  (match-clj? [_ x] (string? x))
  (match-avro? [_ x] (instance? CharSequence x))
  (avro->clj [_ x] (str x))
  (clj->avro [this x path]
    (validate-clj! this x path "string")
    x))
I've had this kind of problem before when dealing with code that uses multi-methods and it's always very difficult to debug. In the past it's been due to recompiling an upstream lib (e.g. with some additional logging), then trying to run some code that uses it, and needing to recompile some other code that I guess has been invalidated by recompiling the lib. That might be the problem here but it's always difficult to identify exactly what needs to be recompiled and was wondered if anyone else had these kind of problems and had figured out a good way of debugging them.

schmee11:10:02

have you seen https://github.com/clojure/tools.namespace? It makes sure to reload all dependent namespaces when you change a namespace

cddr12:10:17

Yeah I've been playing around with that this morning. It seems to introduce other problems (or more likely highlight tech debt in the code-base I'm working in) but it is helping.... Thanks for the link.

Graham Seyffert16:10:31

I’ve had this issue with protocols & records as well… it’s pretty frustrating. My understanding is that this happens when the protocol gets recompiled, but the record doesn’t, and so Clojure doesn’t see the record as implementing the “new” protocol, only the “old” one

Graham Seyffert16:10:09

That issue is related to AOT’d code, but I think results from the same underlying dynamics of protocols…

Graham Seyffert16:10:30

don’t quote me on that 😅

noisesmith16:10:14

a common problem is for instances of the old record (which may for example be implementing the old protocol) to be left hanging around, you can have two Classes with the same name and package but unrelated implementations (and that's what you can get if you reload incompletely and leave old instances hanging around)

Graham Seyffert16:10:57

Yeah, that’s exactly what happens

Graham Seyffert16:10:05

Thanks for clarifying that

awb9911:10:44

Is there a way to require a github project in leiningen project.clj ? I have a dependency of [gg4clj "0.1.0"] (a r wrapper) - this dependency is no longer working. And there is a fix out there but they didn't push a maven repo https://github.com/quan-nh/gg4clj What is the normal way of resolving this?

jumar11:10:11

None that I know of - I usually clone the repo and lein install locally

awb9911:10:31

I will try that.

awb9911:10:48

so how would I then refer to the dependency?

jumar11:10:54

The same way as always - depending on the version you install in the local repo

jumar11:10:43

it's 0.1.0 in project.clj which is rather weird, so perhaps better to change that manually to 0.2.0-SNAPSHOT or something like that?

awb9911:10:19

so then basically it should pop up

awb9911:10:26

and I can require it with that name in my other project.

jumar11:10:00

I'm not following - I think you're mixing up two things.

jumar11:10:16

It doesn't matter how the artifact is called for :require

jumar11:10:31

You do the same stuff as before and shouldn't need to change anything

jumar11:10:54

the new version will just be the name of the jar installed in the local repo which you don't need to care about at all (usually)

awb9911:10:39

IT IS WORKING!!!!

awb9911:10:40

AMAZiNG!!

1
borkdude12:10:12

@hoertlehner There are two alternative solutions: - https://lambdaisland.com/blog/2017-05-17-loading-clojure-libraries-directly-from-github - https://github.com/RickMoynihan/lein-tools-deps Not sure how well the latter works. I've used the first one a couple of times.

awb9912:10:30

@U04V15CAJ Thanks! I will try this out also!

borkdude12:10:55

Lein install is good enough for local development, but for deployment maybe not so.

borkdude12:10:16

You can also make a fork of a lib and deploy it under your own org at clojars.

awb9912:10:02

Yes this is an option I will look into also.

awb9912:10:18

But what I am a little worried is that clojars is already so full of forks.

awb9912:10:37

It is not getting easier if I now start to fork little libraries myself that way also.

borkdude12:10:35

doesn't matter if you publish it under your org, for example com.github.andy27/gg4clj.

borkdude12:10:05

tools.deps is more geared towards using deps directly from git, so you could also consider using that

awb9912:10:51

I get it that it does not fuck up other libraries; however I can only tell from my own experience that I spend A LOT of time to find out which fork is the best one to use. And by putting everything on clojars, it does not make it easier for a developer to find the best dependencies. What is missing really are "suggested dependencies"

alexmiller13:10:12

as an aside this "I spend A LOT of time to find out which fork is the best one to use" is maybe an issue someone should file at clojars to think about. Might be useful to have someone think about this top-down.

2
Ramon Rios14:10:10

Guys, i need to write user acess to certain views of my application. Do you know some library or how to create a acess level function in re-frame?

rickmoynihan16:10:05

Is there a way to configure printing of the full stack trace by default at the REPL in clojure 1.10? i.e. to get the same printing as this clojure --report stderr -e '(throw (ex-info "foo" {}))' but via clojure --report stderr -r

rickmoynihan16:10:08

it seems there isn’t an option to do that

rickmoynihan16:10:28

obvs can access *e

rickmoynihan16:10:55

or use a different repl I suppose

andy.fingerhut16:10:48

Defining your own REPL interaction function is certainly one way -- I cannot think of another off hand. At least in one Stuart Halloway talk he demonstrated this, and it looked pretty straightforward.

alexmiller16:10:34

the default repl has never done this (and personally I think you rarely want it)

alexmiller16:10:09

but yes, you can start your own repl with whatever exception handler you want

👍 1
dpsutton17:10:25

i imported something :as d and then realized i needed a different ns :as d. What's the best way to override it?

vemv19:10:54

the best way is to use clojure.tools.namespace.repl which manages these for you 🙂 I just (refresh) and the aliases are swapped cleanly

hiredman17:10:24

I am super lazy and would just go with d2

😆 1
hiredman17:10:46

but if you look at the namespace related functions one of them is for removing aliases I believe

hiredman17:10:27

additive changes: it's a mindset

clj 1
dpsutton17:10:41

ha. thanks!

danielgrosse18:10:07

Is it possible to make mixed clojure java projects with a deps.edn? Similar to the java-source-paths in leiningen?

seancorfield18:10:05

Clojure can be run from source. Java requires a specific javac compilation step. So you either need to manually compile the .java files to .class on your classpath, and then run clj, or you need to put the (compiled) Java code in its own artifact to be depended on by deps.edn.

seancorfield18:10:00

(in theory you could use the clj -e option to shell out to run javac and then combine steps via aliases but that feels a bit of a hack)

danielgrosse18:10:51

How could I import the generated class in the target path in a clj namespace? Simple using the package name doesn't work.

seancorfield18:10:14

@danielgrosse Is that "target path" on your classpath when you start clj?

seancorfield18:10:05

It needs to be included in :paths (or :extra-paths if you're only adding it via aliases you use when running clj).

seancorfield18:10:06

@danielgrosse Here's a quick example I just knocked up to illustrate this https://github.com/seancorfield/java-clojure-example

seancorfield18:10:21

You only need -A:compile when the Java code changes (or when you're starting off). clj -m my.main will run the main program on subsequent runs.

seancorfield18:10:20

Note that if you run clj -A:compile on its own, it will "hang" for 60 seconds waiting for agents to shutdown -- that's expected but perhaps a bit annoying. If you run clj -A:compile -m my.main then running the main program will shutdown the agents and it will exit immediately.

seancorfield18:10:23

Hope it helps.

danielgrosse18:10:12

Thanks for the effort. I solved it already by adding the class path to the src file. Was just for a POC.

awb9919:10:06

I have a map of vecs {:series-a [1 2 3] :series-b [4 5 6]}. In order to do pretty-print-table I need to convert it to a vec of maps [ {:series-a 1 :series-b 4} {:series-a 2 :series-b 5} {:series-a 3 :series-b 6} ]. I know that I can map simultaneously over multiple vecs, but I guess I have to apply the keys to that. Does someone know how to do that? I seem not to be able to do that.

andy.fingerhut19:10:43

Is it reasonable to assume that all values in the map are vectors, and they all have the same length as each other?

borkdude19:10:18

@andy.fingerhut you just got a shoutout for rrb vector on Apropos https://www.youtube.com/watch?v=PzyUpvTwu7I

andy.fingerhut20:10:19

Cool. I see from some comments that I am not the only one that hears choppy audio.

1
andy.fingerhut19:10:36

@hoertlehner Here is a function that gets part of the way there. Ask again if you would like help completing it from there:

(def m1 {:series-a [1 2 3] :series-b [4 5 6]})
(defn all-nths [m idx]
  (into {} (for [[k vector-val] m]
             [k (vector-val idx)])))
(all-nths m1 0)
;; {:series-a 1, :series-b 4}
(all-nths m1 1)
;; {:series-a 2, :series-b 5}

awb9920:10:12

(defn pp-flip [m] (let [first-series (first (vals m)) size (count first-series) one-row (fn [i] (all-nths m i)) row-idx (range size) ] (vec (map one-row row-idx)) ))

awb9920:10:24

You helped me with the missing puzzle!

awb9920:10:12

It is amazing how data can be transformed!

awb9920:10:24

But sometimes my head is exploding....

andy.fingerhut20:10:49

Understood. Best to try taking it in small pieces, e.g. take that function all-nths and see if you understand exactly what it is doing, and why. There are things in there like for to loop over all key/value pairs in a map, producing a different key/value pair as a vector of two elements, then sending the result to (into {} ...) to create a map from that sequence of pairs, that are very generally useful in many situations.

awb9923:10:00

It's I do understand your code. No problem with that. But when I try to do it myself, I read clojure docs, and find that the docuentation is very compact. One really has to know how things work in order to come up with an idea how to do it.

awb9919:10:04

niceeeeeeeeeeeeeeeeeeeeeeeeee