Fork me on GitHub
eccentric J00:09:24

This is going STRAIGHT to the brain bin


What is this screenshot from? Looks neat.

eccentric J17:09:32

It’s I’ve been using it for notes, todos, and docs since 2016 but recently discovered Zettelkatsen and created a database in Notion for it. It’s working quite well!

eccentric J00:09:21

(map inc [1 2 3])
;; => [2 3 4]
(map #(update % 1 inc) {:a 1 :b 2 :c 3})
;; => ([:a 2] [:b 3] [:c 4])

eccentric J00:09:55

Could that be considered an example of Clojure’s polymorphism or is there a different term for it?


so the first thing that happens is seq is called on your map


that’s kind of polymorphic, in that different data structures implement seq in different ways


maps return a sequence of map entries


you can call key or val on each entry


map entries are also vectors, so you can get assoc or update by index (like you just did)


So that’s also kind of polymorphic


But usually when people talk about Clojure’s polymorphism, they’re talking about the user-level facilities: protocols and multimethods

eccentric J01:09:58

I recall in a talk Rich had a $5 word for that but maybe I’m mis-remembering?


for protocols and mulitmethods?

eccentric J01:09:27

Not quite. For that ability to operate on vectors, hash-maps, sets, strings with the same collection functions if I remember right.


ah, yeah. I dunno.


It's all about abstractions.


Am I wrong or — since update-in does not take the target map as the last argument, I cannot use it in a threaded expression?


Ok seems like I was wrong


@vincenz.chianese It might sound dumb, but you can maybe improve your code by having named functions broken out


instead of


(-> current-state       
    (update-in [matchWinner :score] inc)


(defn increment-score-for [game-state player]
  (update-in game-state [player :score] inc))


(-> current-state
    (increment-score-for matchWinner))

👍 3

Yeah, I guess that might be another thing to do!


Hi! Would you choose Leiningen or cli-tools for a new project and why? Does anyone use clj-tools on Windows?


Definitely the latter. It's much more simple and much more composable. deps.edn is also just an EDN map, whereas project.clj is not - a tool cannot simply parse it without using Leiningen code.


Leiningen works great and gets the job done, try both and go with the one that makes the most sense to you


I'm eager to try cli-tools but current Windows implementation requires to change Powershell script security settings which I don't want to (maybe because I don't know nothing about it)


That's why my second question is about Docker


Maybe I'll stick with Leiningen for a while. I can change it later, can't I?


@UEQDV142J I have two Windows machines that I do Clojure work on -- but I use WSL2 (and Ubuntu) and linuxbrew (the Linux version of Mac's brew/homebrew package manager) so I install/update the Clojure CLI via brew on both Windows machines (in Linux) and on my Mac as well.


A lot of tutorials still feature Leiningen, so there's no harm in having both Leiningen and the Clojure CLI on your system.


Also, if you want to use Powershell but don't want to deal with the security stuff, you could install Scoop (a Windows package manager) and then install the Clojure CLI -- and various other useful Windows tools like Babashka and clj-kondo -- using Scoop.


Also, if you have any questions about the CLI tools on Windows, or you get stuck, there's a #clj-on-windows channel.

👍 3

Scoop also requires the security setting from Powershell


Oh, I thought it used some local installation like brew to circumvent that? Good to know.


To install scoop, you need to enable some security setting


@UEQDV142J If the Powershell security setting is absolutely a dealbreaker, here is a port of the Clojure CLI that is just 1 binary which you can place anywhere on your path:


(it's been a while, I don't remember having to change that, but I guess that's less worrisome than needing to do it for some random .ps1 script off the Internet 🙂 )


It says so on : > Set-ExecutionPolicy RemoteSigned -scope CurrentUser


@U04V70XH6 if you enable all the developer experience settings in windows 10 I think it changes that setting as well.


There’s also a -Scope Process option that only applies to the current session that may work for the install, but I suspect scoop relies on it being set persistently since I think it also uses ps scripts for its packages.

oxalorg (Mitesh)11:09:38

If you're new (like me) I'd suggest going with lein. Just use it, and start writing clojure/business code. You can forget about it until you hit a roadblock and then re-evaluate.


Is it possible to use Docker Clojure image on Windows with VSCode and Calva?


@U04V15CAJ Can speak to that in detail since he just set up Docker/VS Code/Calva and gave a great talk at WSL Conf recently about it.


I've only used Docker from WSL2, not from Powershell / cmd.exe. Personally I don't run Clojure in docker, but all the other stuff like Postgres etc. VSCode has great support for connecting to remote machines or Docker containers, so you can run your entire dev env in a Docker container if you want.

👍 3

Yeah, my setup is Docker via WSL2 (and I actually run Atom via WSL2 as well but I know VS Code has a great "remote" option to run on Windows but talk to code etc on WSL).


That too. In WSL2 it's just a matter of installing the command line script and then typing code, and tadaa, it works.

Vincent Kowalsky22:09:31

Is there standard function in clojure that lets you create the cartesian product of functions? I.e. some function X such that ((X f1 f2) x y) = ((f1 x) (f2 y))?

Chris O’Donnell22:09:01

I don't know of a standard function that does exactly that, but you could accomplish something similar with

(map (fn [f v] (f v)) [f1 f2] [x y])


@U0DUNNKT2 no, the point, if understand it correctly, is to apply (f1 x) to (f2 y)

Chris O’Donnell22:09:23

Ah, it was unclear to me if that return was supposed to be a list or a function invocation


And it's not really a Cartesian product either way. That would be [[(f1 x) (f1 y)] [(f2 x) (f2 y)]] or something like that. The juxt function could help with that, maybe.


(defn X [f g] (fn [x y] ((f x) (g y)))) , or something


Then the map answer should do the trick, indeed


(map #(%1 %2) [f g] [x y]) , I guess


Huh, so "Cartesian product of functions" != "Cartesian product of collections of functions and arguments". TIL

(defn X [f1 f2]
  (fn [x y]
    [(f1 x) (f2 y)]))

Vincent Kowalsky20:09:13

Yes, exactly this. I was just wondering if that exists out of the box. Juxt is similar, but it applies all functions to the same argument rather than creating a n-ary function.