Fork me on GitHub
#beginners
<
2022-06-25
>
mariownyou14:06:49

Hello, im struggling with -> and ->> can you help me: do we need to use -> or ->> in this example, and how would do this 🙂

(defn set-p [im i j]
  (set-pixel (+ i (first offset)) (+ j (last offset))
    (apply color (map (fn [c] (+ c 10)) (rgba (get-pixel im i j))))))

1
zugnush15:06:25

(defn set-p [im i j] (->> (get-pixel im i j) rgba (map (fn [c] (+ c 10))) (apply color) (set-pixel (+ i (first offset)) (+ j (last offset)))))

mariownyou16:06:21

wow, thank you very much. It is working :0

zugnush01:06:56

You might want to see if your editor can be made to do the refactoring for you. Then you can toggle backward and forward. NB automated refactoring might give you a thread starting with just j as the first form, which can be passed to (get-pixed im i) in a thread-last but is obviously not as clear.

Gabriel Kovacs17:06:14

Hi! I am going through the "Web development with Clojure" book. I am using VsCode and I also have clj-kondo. Kondo complains about the following code: (defn handler [request-map] {:status 200 :headers {"Content-Type" "text/html"} :body (str "<html><body> your IP is: " (:remote-addr request-map) "</body></html>")}) I get a Mismatched bracket: found an opening { and a closing ) .... Is there something I can configure in Kondo to make it go away ? Thx!

dpsutton17:06:29

can you post a screenshot? I copied that code and not seeing the same error

dpsutton17:06:44

also you can use triple backticks to post code formatted text

(defn handler [request-map]
    {:status 200 :headers {"Content-Type" "text/html"}
     :body (str "<html><body> your IP is: "
                (:remote-addr request-map)
                "</body></html>")})

dpsutton17:06:03

did you copy this from somewhere?

dpsutton17:06:59

and can you evaluate this at the repl?

dpsutton17:06:58

i'm wondering if you copied it and maybe there are some weird { characters that aren't what yo uthink they are

Gabriel Kovacs17:06:00

I typed it and I also copied it and the result was the same. I had no error when evaluating it. That is why I assumed that it's a configuration issue.

dpsutton17:06:18

weird. then sounds like a bug of vscode

dpsutton17:06:40

there's a #vscode and #calva channel that can give you some more specialized help

Gabriel Kovacs17:06:23

Thx for the Info!

Michaël Salihi18:06:06

Did you use clojure-lsp?

Gabriel Kovacs18:06:55

Not that I am aware of

borkdude18:06:49

Can you maybe post the while file as an attachment here? There may be something weird in your file

Gabriel Kovacs18:06:22

This is the file:

Gabriel Kovacs18:06:45

For completeness: I am using VsCodium Version. 1.68.1

Gabriel Kovacs18:06:03

It's not such a big issue, for me at least. I just got confused 😄

borkdude18:06:20

Does the error persist when you restart it? And can you maybe try VSCode too, just to check?

Gabriel Kovacs18:06:57

Restarting VsCodium solved the problem.

1
Gabriel Kovacs18:06:25

Sorry for the inconvenience.

❤️ 1
Michaël Salihi18:06:28

Yes for me, it's editor side issue. If you run clj-kondo --lint src via cli directly, you shouldn't have theses errors.

Michaël Salihi18:06:27

Our messages crossed, perfect if it's solved. 🙂

😁 1
Gabriel Kovacs18:06:33

Ok, good to know.

dpsutton18:06:33

no inconvenience at all. glad you got it resolved

👍 1
❤️ 1
Michaël Salihi18:06:03

FYI Seems Calva use clojure-lsp under the hood and clojure-lsp use is proper clj-kondo version. https://calva.io/clojure-lsp/ Myself I'm not using VSCode but Emacs with clojure-lsp and I experience sometimes these sort of lint errors when modifying function & co. I have to manually refresh the file/buffer to get the "real" linter information.

Gabriel Kovacs18:06:29

Thx for the Info! Now that I know this, I will just restart if something is fishy 🙂.

pez20:06:27

You probably should not use the clj-kondo extension since you are using clojure-lsp and get clj-kondo linting that way.

👍 1
Gabriel Kovacs17:06:56

Does it make sense to look into Luminus or should I skip it and go for Kit?

👂 1
practicalli-john14:06:29

For understanding the overall concepts of a server-side or 'full-stack' application in Clojure, it won't make a lot of difference However, Clojure projects and libraries have been moving to a more data centric implementation It's the implementation of these concept, the config and libraries used that to me are the difference between kit and Luminus. I would suggest Kit because it has more of this data centric approach. Reitit is a really nice way of defining routes (and can use ring handlers & middleware server side),and Integrant (although a bit of a learning curve) is very useful when a system has multiple components (http server, logging, dn connection, routing, etc. If you want the very basics, then take a look at https://practical.li/clojure-web-services/

Gabriel Kovacs14:06:29

Tank very much for the information! I appreciate you taking the time to explain the difference 🙂.

👍 1
tbtb21:06:05

Is there a way to do something like partition-by but where it creates a new group whenever the value is true, rather than when it changes? I've written a reduce version, but I assume I'm missing a trick with partition-by or another function

(->> [1 3 2 4 1 2 3]
       (reduce
        (fn [acc n]
          (if (odd? n)
            (conj acc [n])
            (update
             acc
             (dec (count acc))
             #((fnil conj []) % n))))
        []))
;; => [[1] [3 2 4] [1 2] [3]]

Martin Půda05:06:56

Try this:

(->> [1 3 2 4 1 2 3]
     (partition-by (let [v (atom 0)]
                     #(if (odd? %) 
                        (swap! v inc) 
                        @v))))

=> ((1) (3 2 4) (1 2) (3))