Why is thread-last not able to resolve the % here?
(defn avg-noise-index [coll1 coll2]
(->> (map noise-index-pairwise coll1 coll2)
(reduce +)
(/ % (count coll1))))
good explanation
I tried as-> and it worked. Thank you!
I assume you want this part (/ % (count coll1))
to be a lambda? If so youβd need to add #
. So it would look like this #(/ % (count coll1))
You might be looking for as->
%
only works in the context of an anonymous function ie #(/ % 5)
If you want to go the lambda route, don't forget to wrap it in an additional set of parens, otherwise it will return the function
I have a struct in my program that stores some variables about stock-count, stock-price, etc I am not sure how I should approach this in a functional way... any suggestions?
the values would somehow have to change I think, and I need to keep track of the initial values
@sunchaesk atoms are useful for holding on to data. you can change the value of an atom using swap! which takes a function to apply to the data, or reset! which sets the data anew. if you are storing your values in a map, you can use something like (swap! atom assoc key value)
and if it is nested you can rely on assoc-in [:path :to :value]
in general I think what you are looking for is swap!
Thanks! That's a good idea
Hmm okay thank you. I thought there was some way to manually place arguments in positions that arenβt the last position
youβd want as->
if you want to be able to control the position
also #()
can prove surprising when used with arrow macros. it expands to (fn [%] (... %))
so the arrow would end up inserting your thing at the tail of that. while awkward you'd need to use (#(/ % (count coll1)))
for that
(loop []
(if-let [pom (try
(read-pom* url)
(catch java.net.ConnectException e
(if (= "Operation timed out" (ex-message e))
(log/error (str "Fetching pom from " url " failed because it timed out, retrying"))
(throw e))))]
pom
(recur)))
βοΈ surely there is a more elegant way to write this?
Hi, I'm Pattern-chaser, a retired firmware designer of many years. I've programmed with many languages over the years, but mainly the old ones. In order of my usage (most used first): C, ASM, C++, then BASIC, Pascal, Fortran, and a bit of C#. All prehistoric. π
And now you are beginning Clojure?
I've fancied Clojure for quite a while, but (as you can see, above) my experience is with very different languages.
My current project is a Windows file-manipulation task, a program to checksum my music files, to verify them prior to backup. It needs to be very fast, as I have 100,000+ music files to check, and I don't want it to take all year! π Is this a task I could approach with Clojure, do you think?
I always fancied Lisp too, but never found the opportunity. π
I do not know. Sounds like the main bottleneck will be IO (running CRC32 or whichever fast checksum you prefer).
since you don't care about being cryptographically secure, something like xxHash would be a good choice
(or (try ...) (recur))
But if you want something more complete/robust, diehard
works well https://github.com/sunng87/diehard
Well, of course π Thanks @clojurians-slack100 - Iβm changing someone elses code, so minimal intervention.
what would be the bestway to handle maps(google maps/ mapbox) in clojure -> integrate it in js or handle it with clojure
im going to add live tracking on the map. app is not yet developed. I'm trying to add map to the pingcrm project
so would be find by either of the approach end goal is to get comfortable with clojure projects
Hard to provide unconditional advice without understanding a bit more about what you are trying to do.
Is your app server-side rendered (written in Clojure and generating HTML), or does it already have a ClojureScript front end?
Most of those are younger than LISP π
@xx.slack fair point! π