beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
2021-05-31T00:36:59.170600Z

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

sova-soars-the-sora 2021-05-31T23:01:08.190300Z

good explanation

2021-06-01T00:42:13.190700Z

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

πŸ‘ 2
aratare 2021-05-31T00:42:23.170800Z

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

lsenjov 2021-05-31T00:53:22.171Z

You might be looking for as->

lsenjov 2021-05-31T00:53:52.171200Z

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

lsenjov 2021-05-31T00:54:22.171400Z

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

Chris K 2021-05-31T01:11:50.172500Z

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 K 2021-05-31T01:12:21.173200Z

the values would somehow have to change I think, and I need to keep track of the initial values

sova-soars-the-sora 2021-05-31T03:39:54.174900Z

@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 K 2021-05-31T16:33:19.188Z

Thanks! That's a good idea

2021-05-31T05:22:24.176200Z

Hmm okay thank you. I thought there was some way to manually place arguments in positions that aren’t the last position

aratare 2021-05-31T05:26:38.176400Z

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

valerauko 2021-05-31T05:37:10.176600Z

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
1
danieroux 2021-05-31T13:58:45.178700Z

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

danieroux 2021-05-31T13:59:05.179200Z

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

Pattern-chaser 2021-05-31T14:50:55.181800Z

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. πŸ˜‰

πŸ˜€ 1
πŸ‘‹ 11
Nom Nom Mousse 2021-06-01T07:24:36.191600Z

And now you are beginning Clojure?

Pattern-chaser 2021-06-01T08:15:51.191900Z

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

πŸ™Œ 1
Pattern-chaser 2021-06-01T08:17:27.192200Z

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-chaser 2021-06-01T08:18:28.192400Z

I always fancied Lisp too, but never found the opportunity. 😞

Nom Nom Mousse 2021-06-01T08:21:24.192600Z

I do not know. Sounds like the main bottleneck will be IO (running CRC32 or whichever fast checksum you prefer).

lunik1 2021-06-01T21:25:05.226700Z

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

walterl 2021-05-31T14:51:38.182600Z

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

walterl 2021-05-31T14:54:30.186500Z

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

danieroux 2021-05-31T15:45:00.187400Z

Well, of course πŸ™ƒ Thanks @clojurians-slack100 - I’m changing someone elses code, so minimal intervention.

πŸ™‚ 1
sandeep 2021-05-31T17:01:56.188300Z

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

sandeep 2021-06-01T14:02:26.204900Z

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

sandeep 2021-06-01T14:04:49.205200Z

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

seancorfield 2021-05-31T17:42:27.188500Z

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

seancorfield 2021-05-31T17:42:55.188700Z

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

lunik1 2021-05-31T17:43:45.188900Z

Most of those are younger than LISP πŸ˜‰

sova-soars-the-sora 2021-05-31T23:02:27.190500Z

@xx.slack fair point! πŸ˜„