Fork me on GitHub
#beginners
<
2020-03-05
>
Kevin10:03:08

Hi, I'm having some issues with resolving dependencies. Maybe this is common? I have 2 Libraries, A and B, And 1 application, C. A is required by B, B is required by C. A's classpath doesn't get added to application C. Resulting in the following error: Could not locate A/core__init.class I can resolve this by adding A to C's project.clj dependencies. However C isn't using A directly, so it doesn't make sense to me that I have to add A. Any ideas?

kelveden10:03:07

Is A a "provided" dependency of B? Also lein deps :tree may give some hints as to what's going on.

Kevin11:03:47

It's not provided, it's a direct dependency. I tried to also include it in provided but both didn't work. Could be related to the fact that B is a private repo included through git

kelveden11:03:54

Hmm yeah I'm not familiar with git-down but a brief scan of docs suggests that it effectively means that B is being physically included in the source for C? If so, how are the dependencies for B being included?

kelveden11:03:59

i.e. is it possible that leiningen just isn't processing the project.clj for B at all? (In which case, none of the transitive dependencies - including those of A - would be loaded.)

Kevin11:03:40

Yeah that's what I'm suspecting. I'm pretty sure this is a git-down related issue. I'll have to look more into that. Thanks

👍 4
andy.fingerhut10:03:36

Are you using Leiningen? something else?

andy.fingerhut10:03:48

Is B published somewhere publicly, like Maven central or Clojars, or is it something private to you and/or your organization?

andy.fingerhut10:03:42

Reading again, you mention a project.clj file, so that means yes for your using Leiningen. Perhaps however B was published as a JAR file does not correctly define A as something that B depends upon?

Kevin11:03:17

A is public, B is private organization repo that we include through git-down. Maybe that's the problem.

Hiroyuki K.13:03:32

Hello, everyone. I'm looking for a mate who can help me on my business. I'm willing to pay monthly. Budget would be 500 ~ 2000USD. Please DM me. Thank you.

4
vxe15:03:44

getting a dependency exception like this when trying to include clojupyter in my project

Caused by: clojure.lang.ExceptionInfo: Insufficient `com.taoensso/encore` version, you may have a dependency conflict: see  for solutions. {:min-version "2.105.0", :your-version "2.91.0"}
	at taoensso.encore$assert_min_encore_version.invokeStatic(encore.clj:1007)
	at taoensso.encore$assert_min_encore_version.invoke(encore.clj:998)
is there a standard way to resolve issues like this using clj deps? The naive solution of just adding com.taoensso/encore {:mvn/version 2.105.0} to deps.edn doesn't seem to be working

Alex Miller (Clojure team)15:03:35

you need quotes around 2.105.0

vijay16:03:21

still doesn’t work

Alex Miller (Clojure team)16:03:25

can you share full deps.edn and your output

Alex Miller (Clojure team)16:03:48

"doesn't work" is not useful

vijay17:03:47

see error message i put quotes when I tried it the first time

Alex Miller (Clojure team)17:03:26

is that commented line what you were trying? if so, that's not correct deps.edn syntax

Alex Miller (Clojure team)17:03:13

override-deps only go in aliases, but I think you actually want that in your normal deps so it overrides the transitive version

👍 4
Alex Miller (Clojure team)17:03:40

so just include com.taoensso/encore {:mvn/version "2.119.0"} in your :deps

vxe05:03:25

in case anyone finds this via google the correct answer in exclude sente as it appears to be incompatible with clojupyter https://gist.github.com/vxe/e30fe65c78802bc746ce24857be616a0#file-gistfile1-txt-L1

hindol16:03:23

Is the a good log analysis library in Clojure? I need to extract structured info from unstructured log lines. RegEx is helpful, but I also need to maintain context from previous line. For example, 1) Starting upgrade of node X 2) Container A upgraded successfully 3) Container B upgrade failed Now I need to output, {:node "X" :success ["A"] :failure ["B"]} What would be your approach to this?

bfabry16:03:02

is this a standard log format or something of your own?

hindol16:03:06

Our own. But changing the logs now might break things elsewhere.

bfabry16:03:37

well I don't really have any good ideas sorry. if it were me I'd be tempted to look at instaparse

☝️ 4
manutter5118:03:45

My inclination would be to look into using Instaparse to write a parser that will convert each individual log entry into a useful hashmap, and then run some kind of aggregator function over all the hashmaps.

Grigory Shepelev16:03:41

Hello. I'm continuing digging deeper into Clojure and I don't quite understand definterface from official documentation. Could you give some more examples please?

kelveden16:03:37

Perhaps the examples from clojuredocs help? http://clojuredocs.org/clojure.core/definterface

Grigory Shepelev16:03:19

yeah. I saw. I don't understand them.

bfabry16:03:50

are you familiar with java and java interfaces?

Grigory Shepelev16:03:44

Nope. I came from Haskell. I'm looking for a way to specify function's return (type?). Spec is basiclly for checking the argument themself.

Grigory Shepelev16:03:26

It seems like definterface "acts" on Records

Grigory Shepelev16:03:01

Is there any way to to that?

Grigory Shepelev16:03:00

Like: saying what expected from function to be result. And if it's not what's exprcted — throw and error with an explanation.

Grigory Shepelev16:03:55

Or I can have the same by using spec inside the function's body? :thinking_face:

bfabry16:03:05

sorry got distracted. you'll need to read up on and understand java interfaces to understand definterface

Grigory Shepelev16:03:25

My patters of thinking are somewhat locked on static type systems...

bfabry16:03:40

interfaces are very much a static type system thing

bfabry16:03:03

I'm trying to remember my haskell to give you the right analogy but it's been so long

bfabry16:03:12

typeclass, that's it. an interface is java's equivalent of a typeclass. but of course much more limited/less static than haskell

hindol16:03:49

Also called trait in some languages.

bfabry17:03:20

as an aside: in 10ish years of using clojure I don't think I've ever used definterface

hindol17:03:53

It will be needed though when you want Java developers to also use your Clojure library.

FiVo17:03:16

Hey, I am playing around with datafy/nav and rebl.

FiVo17:03:47

(require '[clojure.datafy :as d])
(require '[clojure.core.protocols :as p])
(defrecord D [a b]
  p/Datafiable
  (d/datafy [this]
    (-> (into {}
              (map (fn [[k v]] [k (if (instance? D v) '=> v)]))
              this)
        (assoc :type "D")))
  p/Navigable
  (d/nav [this k v]
    (get this k)))

FiVo17:03:56

I am wondering why the following doesn't let me see the nested D's in REBL. (D. 1 (D. 2 (D. 3 5)))

FiVo17:03:26

I mean why can't navigate into them.

David Pham17:03:47

Is it possible to require different namespace depending on your build? Like if I want to build :a with lein it will require namespace foo, but if I build :b it will require namespace bar?

bfabry17:03:32

it's possible, I can't think of a situation where I'd recommend it. what's brought this about?

bfabry17:03:28

my first reaction is "create a protocol/multimethod and inject the dependency instead" btw

David Pham20:03:08

In the case of CLJS with React Native and React. I would like to abstract the UI layer and have different implementations of component depending on the target.

bfabry21:03:24

yeah a protocol/multimethod/passed-in-function is the appropriate way to create an abstraction, not namespaces

David Pham06:03:13

In this case the build should be passed to all functions?

David Pham06:03:34

Or you would initiate the closures at the beginning of the programs?

bfabry20:03:39

I would build your protocol implementing or multimethod dispatching object at whatever time you first know which to choose (which is probably start up) and then pass it down through each function as a parameter

sol sarratea20:03:03

hey! I am trying to build an app with overtone + reagent+ figwheel + ajax , but I am having lots of troubles with dependencies. Is anybody interesting in maybe generating a template for building this kind of apps? or just wanna help me with this particular project 🙂 ?

Michael Thurmond20:03:31

what command did you run from the command line to create the project?

sol sarratea20:03:56

I tried to start building by myself, but have problems connecting my server with clojurescript/figwheel server

sol sarratea20:03:01

so i run lein new reagent-ajax ...

sol sarratea20:03:15

which has a nice template, but dependencies are killing me

sol sarratea20:03:23

i tried to fix it with lein tree :deps

sol sarratea20:03:35

but did not work

Michaël Salihi20:03:11

> which has a nice template, but dependencies are killing me @mssarratea Did you try with Shadow-CLJS instead Lein/Figwheel ? For me when I begin last year, it was more clear and simplier.

sol sarratea21:03:02

I did not figure out how to set the server port, so to connect it with my backend clojure app

sol sarratea21:03:28

have you been through the same? can I see your code 🙃

Michaël Salihi15:03:52

Do you tried to communicate with your Clojure backend with AJAX from CLJS Reagent right ? Any information about your backend ? REST API ? Another ?

Adrian Smith21:03:38

lein new re-frame is a nice template, might be worth doing that to get reagent/shadowcljs setup then remove re-frame if not needed

acim122:03:02

Say I want to return a value in a certain scenario, but just log an error and return nil (log function just returns nil) in another, is this weird?

(if good?
 val
 (log-err "No good!))

bfabry22:03:21

imo fine

👍 4
bocaj23:03:49

How would you tranform

{:x [1 2 3]
 :y [4 5 6]}
into
[{:x 1 :y 4}
 {:x 2 :y 5}
 {:x 3 :y 6}]

teodorlu09:03:06

Multi-arity map:

(let [old-data {:x [1 2 3]
                  :y [4 5 6]}]
    (map (fn [x y]
           {:x x :y y})
         (:x old-data)
         (:y old-data)))
  ;; => ({:x 1, :y 4} {:x 2, :y 5} {:x 3, :y 6})

hiredman23:03:55

erm, map is going to be better actually

Pavel Klavík23:03:22

ya, use map, it allows to take multiple sequences as arguments

Pavel Klavík23:03:19

something like

(let [{:keys [x y]} input]
  (into [] (map (fn [xval yval] {:x xval :y yval}) x y)))

bocaj23:03:24

Thanks, got stuck in reduce land

bocaj23:03:33

I'm trying to have this work for arbitrary keys, but guaranteed values have the same number of elements, I've got this far, missing

:ab
(def m {:x [1 2 3]
          :y [4 5 6]
          :z [7 8 9]
          :ab [10 11 12]})
  (let [ks (keys m)
        vs (vals m)]
    (map #(zipmap ks %) vs)
    )

bocaj23:03:23

;=> ({:x 1, :y 2, :z 3} {:x 4, :y 5, :z 6} {:x 7, :y 8, :z 9} {:x 10, :y 11, :z 12})

bfabry23:03:58

(let [ks (keys m)] (into [] (apply map #(zipmap ks %) (vals m))))

bfabry23:03:06

you forgot the apply

hiredman23:03:12

it's a join

bfabry23:03:27

and I forgot the &

(let [ks (keys m)]
  (into [] (apply map #(zipmap ks %&) (vals m))))
[{:x 1, :y 4, :z 7, :ab 10} {:x 2, :y 5, :z 8, :ab 11} {:x 3, :y 6, :z 9, :ab 12}]

hiredman23:03:52

(let [m {:x [1 2 3]
         :y [4 5 6]
         :z [23 19 34]}]
  (reduce
   (fn [a b]
     (clojure.set/join a b {:nth :nth}))
   (for [k (keys m)]
     (map-indexed
      #(assoc %2 :nth %1)
      (for [item (k m)]
        {k item})))))

;;=> #{{:x 3, :nth 2, :y 6, :z 34} {:x 1, :nth 0, :y 4, :z 23} {:x 2, :nth 1, :y 5, :z 19}}

👍 4
bocaj23:03:33

I did want the nth next, so thanks!