Fork me on GitHub
Rob Haisfield00:05:59

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))))


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

Rob Haisfield05:05:24

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

👍 1
Rob Haisfield00:06:13

I tried as-> and it worked. Thank you!

👍 2
Chris K01:05:50

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?

Chris K01:05:21

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!

👍 1
Chris K16:05:19

Thanks! That's a good idea


(loop []
    (if-let [pom (try
                   (read-pom* url)
                   (catch e
                     (if (= "Operation timed out" (ex-message e))
                       (log/error (str "Fetching pom from " url " failed because it timed out, retrying"))
                       (throw e))))]


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. 😉

👋 11
😀 1

Most of those are younger than LISP 😉

Nom Nom Mousse07:06:36

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.

🙌 1

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. 😞

Nom Nom Mousse08:06:24

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

s stan17:05:56

what would be the bestway to handle maps(google maps/ mapbox) in clojure -> integrate it in js or handle it with clojure


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?

s stan14:06:26

im going to add live tracking on the map. app is not yet developed. I'm trying to add map to the pingcrm project

s stan14:06:49

so would be find by either of the approach end goal is to get comfortable with clojure projects