Fork me on GitHub
#clojure
<
2020-09-26
>
Eccentric J00:09:24

This is going STRAIGHT to the brain bin

p-himik06:09:57

What is this screenshot from? Looks neat.

Eccentric J17:09:32

It’s https://notion.so. 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?

potetm00:09:05

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

potetm00:09:36

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

potetm00:09:55

maps return a sequence of map entries

potetm00:09:12

you can call key or val on each entry

potetm01:09:09

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

potetm01:09:31

So that’s also kind of polymorphic

potetm01:09:06

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?

potetm01:09:32

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.

potetm01:09:47

ah, yeah. I dunno.

seancorfield03:09:05

It's all about abstractions.

vncz13:09:44

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?

vncz13:09:41

Ok seems like I was wrong

emccue19:09:39

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

emccue19:09:48

instead of

emccue19:09:25

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

emccue19:09:31

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

emccue19:09:53

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

👍 1
vncz20:09:56

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

evocatus21:09:20

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

p-himik21:09:57

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.

schmee21:09:43

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

evocatus21:09:57

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)

evocatus21:09:18

That's why my second question is about Docker

evocatus21:09:51

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

seancorfield21:09:44

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

seancorfield21:09:13

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

seancorfield21:09:09

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.

seancorfield21:09:02

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

👍 1
borkdude21:09:01

Scoop also requires the security setting from Powershell

seancorfield21:09:38

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

borkdude21:09:54

To install scoop, you need to enable some security setting

borkdude21:09:46

@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: https://github.com/borkdude/deps.clj

seancorfield21:09:52

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

borkdude21:09:00

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

chucklehead22:09:42

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

chucklehead22:09:46

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.

oxalorg11: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.

evocatus21:09:48

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

seancorfield21:09:45

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

borkdude21:09:22

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.

👍 1
seancorfield21:09:26

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

borkdude21:09:39

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

codonnell22: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])

jsn22:09:52

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

codonnell22:09:23

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

p-himik22:09:38

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.

jsn22:09:05

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

jsn22:09:46

Then the map answer should do the trick, indeed

jsn22:09:07

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

p-himik03:09:48

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.