Fork me on GitHub
#beginners
<
2021-06-14
>
seancorfield00:06:12

@orlandomr27 Where is the reference to https://repository.jboss.org/nexus/content/repositories/deprecated/ coming from? Is that part of your custom configuration? I see you have https://repo.enonic.com/public/ in your project.clj file?

omendozar16:06:22

Just for the record @seancorfield io.xapix/paos is now on Clojars so I deleted my .m2 folder, removed the :repositories tag from my project.clj and it’s fine now. 🙂

2
omendozar17:06:40

Searching for another solution I came to clj-soap. While a was playing with it I realize that is very easy to consume a SOAP service as a client, easier than paos. But there are no examples on how to send an array as parameters. I was using a version forked from your repo so I wonder if you have examples on how to do it.

seancorfield17:06:43

@orlandomr27 I couldn’t get clj-soap to do anything useful (which is why it is archived). I ended up using wsdl2java, compiling the Java files and making a JAR, and then using that with clj-http as I recall. But it was years ago — and we no longer use that 2rd party service so we no longer have to deal with SOAP! Yay!

omendozar17:06:38

deal with SOAP it’s horrible, really. Well, I’ll stick to paos then which is working fine so far

omendozar00:06:26

Yes, I’,m using io.xapic/paos for a WSDL Service and they recommend to add enonic repository https://github.com/xapix-io/paos#installation

Because soap-ws depends on a list of external dependencies that are not published in clojars or maven, you need to add them to the project's repository list yourself.

omendozar00:06:21

It worked until 3 days ago, no idea what happened

Erik B Good01:06:00

Hello, I was wondering how I could 'next' on a lazy cycle object and preserver lazyness. Let's say I have (cycle ["A" "B"]). I will get "A" if I call 'first'. I would like to get "B" the next time I would be calling first. Essentially (first (next (cycle ["A" "B"]))) And preserve the lazyness of my object. Thank you..

didibus02:06:18

What you want isn't a functional programming behavior. You're asking for some mutation.

didibus02:06:59

You should rethink what you are doing instead.

didibus05:06:45

But if you really insist, this is a way to achieve something similar to what you are asking:

(defn mut-cycle
  [elements]
  (let [c (atom (cycle elements))]
    (fn[]
      (ffirst (swap-vals! c rest)))))

(def foo (mut-cycle ["A" "B"]))
(foo)
;;=> "A"
(foo)
;;=> "B"
(foo)
;;=> "A"
You cannot do what you want with sequences, because they force you into an immutable use. But you can achieve it with a mutable atom and a function closure like I did. Each time you call the function returned by mut-cycle you get the next element. You can call this infinite number of time, it will keep cycling.

Erik B Good12:06:12

yes I see what you mean @U0K064KQV I will think of another solution that behave in a pure way. Thank you for confirming what I thought

tws20:06:51

maybe a loop. (loop [thing (first my-cycle)] … (recur (rest my-cycle)))

Yang Xu03:06:13

Hello, I installed clojure via homebrew, and I add a new library in deps.edn that located in the clojure installed directory, and then I restart clj, but the library didn' download. Who can tell me which step I have mistake?

solf03:06:47

A first debugging step would be to ask clojure what’s in it’s classpath:

clojure -Spath

Yang Xu03:06:13

Nice skill, and it worked now, thank you.

solf03:06:53

👌 There’s also

clojure -Sdescribe
to check which edn files are loaded

Yang Xu03:06:38

Wow, how such helpful command, thank you again.

popeye07:06:38

I am practising clojure and wrote below code

(def  map1 [ {:size 5 :color "blue" } {:size 7 :color "blue" }  {:color "Orange" :size 8} {:color "yellow" :size 10} ] )
(def  map2 [ {:size 7 :color "blue" } {:size 8 :color "Orange" }{:color "yellow" :size 10}  ])

(defn intersectionexample
  ([s1 s2]
   (if (> (count s2) (count s1))
     (recur s2 s1)
     (reduce (fn [acc item]
               (println s2 "-- " item "---")
               (if (contains? s2 item)
                 (do
                   (update acc :match  conj item)
                   (disj s2 (set item)))
                 (do
                   (update acc :non-match  conj item))
                 ))
             {}
             s1))))

(println (intersectionexample (set map1) (set map2)))

popeye07:06:20

This gave me clojure.lang.PersistentHashSet cannot be cast to clojure.lang.Associative at (disj s2 (set item)) what am I doing wrong!!

solf07:06:59

You can check examples of how to call disj here: https://clojuredocs.org/clojure.core/disj

solf07:06:38

You’re passing (set item) in second arg, however it expects one element per arguments, like this:

(disj #{1 2 3} 2 3 4)

popeye07:06:33

This worked for me

(def st #{{:color "yellow", :size 10} {:size 8, :color "orange"}} )
(println (disj st {:size 7, :color "blue"} ))

popeye07:06:55

but running in reduce is giving issue

solf07:06:01

You can use apply to call a function with the arguments from a collection:

(apply disj #{1 2 3} [1 3])

phronmophobic07:06:48

the error isn't with (disj s2 (set item)) , it's with (update acc :match conj item)

popeye07:06:23

@U7RJTCH6J without disj line of code it is working fine

popeye07:06:32

i added one more code disj

phronmophobic07:06:20

right, the value of acc is the value returned on the previous iteration. putting in the disj means that acc will be a set rather than a map for the next iteration. The first call to the reducing function should succeed and then error on the second call because of the disj

solf07:06:49

@U01J3DB39R6 as a general remark, this kind of code is not going to work as you expect:

(do
                   (update acc :match  conj item)
                   (disj s2 (set item)))
The vast majority of clojure functions are immutable, so this update call is not going to modify acc, but return a new object, and the new object is immediately discarded as you don’t use it for anything

popeye07:06:59

ok I agree, How can I update both acc and s2 ?

popeye07:06:35

I do not want to use contains function from the beginning again of collection item

solf07:06:14

You’ll have to rethink your whole code. This is the challenge of learning functional programming. But in this case you don’t need to update s2 at all. You don’t want to call contains, but there’s actually nothing wrong with that

solf07:06:28

Here’s an excerpt from contains? doc string:

'contains?' operates constant or logarithmic time;
it will not perform a linear search for a value.

solf07:06:19

Since you’re using contains? on a set, the search time is not going to increase linearly with the size of the set

popeye07:06:02

this will check wach element in one map with each element with the other right? this will n*n complexity

solf07:06:22

each contains? call is around~ constant time, so 1, then reduce is n, and… that’s it? so n total

solf07:06:40

or n log n, I don’t know how contains? exactly works with set

popeye07:06:28

so u mean contains? call the thread?

solf07:06:47

there’s no thread here

solf07:06:00

What I mean is that contains? is not O(n)

popeye07:06:15

i meant inner implementation of contains?

solf07:06:26

it’s O(1) or O(log n) per it’s docstring, when used on sets

popeye08:06:01

so you mean how many records available in the both the map, contains work efficiently, right?

solf08:06:12

that’s the point of using a map or set, accessing a key is linear~ time

popeye08:06:31

thanks @U7S5E44DB that helped

👌 2
Michael Stokley14:06:16

accessing a key in a hash map is linear time? or constant time

popeye14:06:23

as the document says for contains, it says logarithmic or constant depends on the data

👍 2
Michael Stokley14:06:03

> that’s the point of using a map or set, accessing a key is linear~ time does the ~ post fix mean "better than"? @U7S5E44DB

solf00:06:00

it means "approximately", as it can be logarithmic time

solf00:06:26

I tried looking up the exact implementation of contains? for sets, but my java-fu is very bad and I didn't find it. Maybe it becomes logarithmic if the size of the set reaches a certain point

quan xing13:06:06

hello, everybody How can I insert the eval exp result into the end of the exp in emacs. I used C-c C-v C-f d is nothing happen

eric wolf17:06:58

hi quan, i tried running C-c C-v C-f d in the cider REPL and got a result in a buffer called cider-result i hope that helps. i've also found that C-c C-e also does an eval and puts the results in the message window.

eric wolf17:06:55

today i learned : if you add dependencies to a project and install bring them in them using lein deps you have to close the cider REPL and restart it (M-x cider-restart didn't seem to work for me) before cider will allow compilation.

noisesmith17:06:10

to be pedantic: you don't install anything by using lein deps , all it does is check for their location in a cache, and load them into the cache if they are currently missing

noisesmith17:06:46

lein isn't an installer, it's a build tool that manages a cache and uses declarative rules to decide which things in the cache a given process should use

noisesmith17:06:58

this is done at startup, and that's why your repl needed to be restarted

noisesmith17:06:24

also, really, "lein deps" should be considered an implementation detail of other tasks - anything you do which uses the project (start a repl, run the app, compile, build a jar) already does that deps task for you

seancorfield17:06:51

There are ways to add new dependencies to a running REPL but they are not widely used right now. lein uses Pomegranate under the hood so you can require that in your REPL and load new libraries without a restart — see https://github.com/clj-commons/pomegranate

💡 5
seancorfield17:06:00

I use the Clojure CLI and deps.edn and a branch of org.clojure/tools.deps.alpha (via my dot-clojure repo files) and that branch — add-lib3 — has a way to load new dependencies into a deps.edn-based REPL (I use this quite a bit so I can keep my REPLs running for weeks).

💡 5
eric wolf17:06:55

Thanks for the clarification. In any case, just wanted to save others the headache of wondering what went wrong when the REPL complains. Also great resources, Sean.

Adam Krivka18:06:32

Is there a way to build a Clojure project to Clojure, i.e. just concat all the files to one (while resolving namespaces etc.)? Like e.g., tell shadow-cljs not to compile to JS/Java, but just give a one big main.cljs/clj file. 🙂

Adam Krivka19:06:44

I rewrote the original message, I hope it helps.

sova-soars-the-sora23:06:32

You could probably write a macro to accomplish this. You want to take all the qualified namespaces and expand them and weave it all into one gigantic main clj/s file? I mean it's doable, although I don't think much effort has been put into this particular direction currently.

popeye19:06:34

i am practising clojure and I have a list as `

(def fruit ({:color "Orange" , :size 8} {:color "yellow", :size 10} {:size 7, :color "blue"}))
How can I add `
{:type "Fruit"}
each element of the list ?

noisesmith19:06:34

that def makes no sense - surely that's [] or the literal is quoted

noisesmith19:06:14

(map #(assoc % :type "Fruit") fruit) returns a new lazy-seq with :type "Fruit" added to each hash

popeye19:06:53

Why `

(map assoc fruit :type "Fruit")
does not work and ?

noisesmith19:06:17

map calls its first arg as a function, with the items of each other arg as args

user=> (map list [:a :b :c] [1 2 3])
((:a 1) (:b 2) (:c 3))

noisesmith19:06:52

so the whole assoc, with all the args, needs to be inside a function that map can use

noisesmith19:06:05

it might be helpful to note that map isn't a special syntax or operator (so it doesn't do magic argument packing / unpacking for readability), it's just a function that calls other functions on elements of collections

Mitul Shah19:06:43

super beginner here, is there an equivalent of a restProps in reagent? ex.

function Greeting({ name, ...restProps }) {
  return <div {...restProps}>Hi {name}!</div>;
}

seancorfield19:06:47

@mitul (defn greeting [name & more] ...)

noisesmith19:06:50

and then into usually being used to replace that interopolation right? never mind I read that wrong

seancorfield19:06:03

more will be a sequence of all the additional arguments passed into the call of greeting. If you’re producing Hiccup output, you’ll need to use into or similar to “unroll” it.

seancorfield19:06:56

Or [name & {:as props}] if you want a hash map there.

phronmophobic19:06:30

I thought the equivalent would look more like:

(defn greeting [{:keys [name] :as m}]
  [:div (dissoc m :name) (str "Hi " name "!")])

💯 2
phronmophobic19:06:24

although @seancorfield’s example is probably how I would write it

(defn greeting [name props]
  [:div props (str "Hi " name "!")])
;; usage
(greeting "Mitul" {:class "greeting"})

Mitul Shah19:06:17

yes this makes sense, thank you so much!

👍 2
Mitul Shah19:06:09

also interesting, props have to be in order when they’re passed through?

Mitul Shah19:06:43

because you didn’t define name="Mitul" , you just passed the actual string?

phronmophobic19:06:49

If you write the function this way. The other version, you would just pass a single map:

(greeting {:class "greeting" :name "Mitul" })

phronmophobic19:06:26

Separating the props and the name is just a matter of preference

seancorfield19:06:45

☝️:skin-tone-2: That would probably be my preferred approach — using a name and an actual hash map rather than key/value pairs — although with Clojure 1.11 that’s less of an issue since you can now pass a hash map into a function that accepts “named arguments”.

🙌 2
popeye22:06:00

I have 2 sets which has n number of maps, where I need to perform whether elements in one map is present in another map or not, this would be a time complexity of n*n , how efficiently I can do in clojure?

hiredman23:06:06

use clojure.set/index instead of just a bare set

noisesmith14:06:22

how is this different from set/intersection? you don't need to compare every map to every map, you just need to check which maps are present in the other set (it will be most efficient if the smaller set is the first arg)

noisesmith14:06:01

never mind, it's fast regardless of arg order

cmd)user=> (time (s/intersection #{{:a 0}} (into #{} (map (partial hash-map :a)) (range 10000))))
"Elapsed time: 5.630487 msecs"
#{{:a 0}}
(cmd)user=> (time (s/intersection (into #{} (map (partial hash-map :a)) (range 10000)) #{{:a 0}}))
"Elapsed time: 4.806462 msecs"
#{{:a 0}}

sova-soars-the-sora23:06:32

You could probably write a macro to accomplish this. You want to take all the qualified namespaces and expand them and weave it all into one gigantic main clj/s file? I mean it's doable, although I don't think much effort has been put into this particular direction currently.