Fork me on GitHub
#beginners
<
2021-05-31
>
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))))

aratare00:05:23

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

lsenjov00:05:22

You might be looking for as->

lsenjov00:05:52

% only works in the context of an anonymous function ie #(/ % 5)

lsenjov00:05:22

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

aratare05:05:38

you’d want as-> if you want to be able to control the position

valerauko05:05:10

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

👍 3
3
Rob Haisfield00:06:13

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

👍 6
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

sova-soars-the-sora03:05:54

@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!

👍 3
Chris K16:05:19

Thanks! That's a good idea

danieroux13:05:45

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

danieroux13:05:05

☝️ surely there is a more elegant way to write this?

walterl14:05:38

(or (try ...) (recur))

walterl14:05:30

But if you want something more complete/robust, diehard works well https://github.com/sunng87/diehard

danieroux15:05:00

Well, of course 🙃 Thanks @UJY23QLS1 - I’m changing someone elses code, so minimal intervention.

🙂 3
Pattern-chaser14:05:55

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

👋 33
😀 3
lunik117:05:45

Most of those are younger than LISP 😉

Nom Nom Mousse07:06:36

And now you are beginning Clojure?

Pattern-chaser08:06:51

I've fancied Clojure for quite a while, but (as you can see, above) my experience is with very different languages.

🙌 3
Pattern-chaser08:06:27

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?

Pattern-chaser08:06:28

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

lunik121:06:05

since you don't care about being cryptographically secure, something like xxHash would be a good choice

sandeep17:05:56

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

seancorfield17:05:27

Hard to provide unconditional advice without understanding a bit more about what you are trying to do.

seancorfield17:05:55

Is your app server-side rendered (written in Clojure and generating HTML), or does it already have a ClojureScript front end?

sandeep14: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

sandeep14:06:49

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