@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?
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. 🙂
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.
@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!
deal with SOAP it’s horrible, really. Well, I’ll stick to paos then which is working fine so far
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.
It worked until 3 days ago, no idea what happened
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..
yes I see what you mean @didibus I will think of another solution that behave in a pure way. Thank you for confirming what I thought
maybe a loop. (loop [thing (first my-cycle)] … (recur (rest my-cycle)))
What you want isn't a functional programming behavior. You're asking for some mutation.
You should rethink what you are doing instead.
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?
A first debugging step would be to ask clojure what’s in it’s classpath:
clojure -Spath
Nice skill, and it worked now, thank you.
👌 There’s also
clojure -Sdescribe
to check which edn
files are loadedWow, how such helpful command, thank you again.
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.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)))
This gave me clojure.lang.PersistentHashSet cannot be cast to clojure.lang.Associative
at (disj s2 (set item))
what am I doing wrong!!
You can check examples of how to call disj
here: https://clojuredocs.org/clojure.core/disj
You’re passing (set item)
in second arg, however it expects one element per arguments, like this:
(disj #{1 2 3} 2 3 4)
This worked for me
(def st #{{:color "yellow", :size 10} {:size 8, :color "orange"}} )
(println (disj st {:size 7, :color "blue"} ))
but running in reduce is giving issue
You can use apply
to call a function with the arguments from a collection:
(apply disj #{1 2 3} [1 3])
the error isn't with (disj s2 (set item))
, it's with (update acc :match conj item)
@smith.adriane without disj line of code it is working fine
i added one more code disj
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
@popeyepwr 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 anythingok I agree, How can I update both acc and s2 ?
I do not want to use contains
function from the beginning again of collection item
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
Here’s an excerpt from contains?
doc string:
'contains?' operates constant or logarithmic time;
it will not perform a linear search for a value.
Since you’re using contains?
on a set, the search time is not going to increase linearly with the size of the set
this will check wach element in one map with each element with the other right? this will n*n complexity
each contains?
call is around~ constant time, so 1, then reduce is n
, and… that’s it? so n
total
or n log n
, I don’t know how contains?
exactly works with set
so u mean contains?
call the thread?
there’s no thread here
What I mean is that contains?
is not O(n)
i meant inner implementation of contains?
it’s O(1)
or O(log n)
per it’s docstring, when used on sets
so you mean how many records available in the both the map, contains work efficiently, right?
yes
that’s the point of using a map or set, accessing a key is linear~ time
thanks @dromar56 that helped
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
accessing a key in a hash map is linear time? or constant time
as the document says for contains, it says logarithmic or constant depends on the data
> that’s the point of using a map or set, accessing a key is linear~ time does the ~ post fix mean "better than"? @dromar56
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.
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.
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
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
this is done at startup, and that's why your repl needed to be restarted
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
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
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).
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.
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. 🙂
Ok, thanks.
i no understand
I rewrote the original message, I hope it helps.
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 ?that def makes no sense - surely that's [] or the literal is quoted
(map #(assoc % :type "Fruit") fruit)
returns a new lazy-seq with :type "Fruit"
added to each hash
Why `
(map assoc fruit :type "Fruit")
does not work and ?super beginner here, is there an equivalent of a restProps
in reagent?
ex.
function Greeting({ name, ...restProps }) {
return <div {...restProps}>Hi {name}!</div>;
}
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))
so the whole assoc, with all the args, needs to be inside a function that map can use
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 (defn greeting [name & more] ...)
and then
never mind I read that wronginto
usually being used to replace that interopolation right?
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.
Or [name & {:as props}]
if you want a hash map there.
I thought the equivalent would look more like:
(defn greeting [{:keys [name] :as m}]
[:div (dissoc m :name) (str "Hi " name "!")])
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"})
☝️: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”.
yes this makes sense, thank you so much!
also interesting, props have to be in order when they’re passed through?
because you didn’t define name="Mitul"
, you just passed the actual string?
If you write the function this way. The other version, you would just pass a single map:
(greeting {:class "greeting" :name "Mitul" })
Separating the props and the name is just a matter of preference
That helped @noisesmith
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?
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)
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}}
use clojure.set/index instead of just a bare set