This is going STRAIGHT to the brain bin
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!
Thanks!
(map inc [1 2 3])
;; => [2 3 4]
(map #(update % 1 inc) {:a 1 :b 2 :c 3})
;; => ([:a 2] [:b 3] [:c 4])
Could that be considered an example of Clojure’s polymorphism or is there a different term for it?
eh, ish
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
I recall in a talk Rich had a $5 word for that but maybe I’m mis-remembering?
for protocols and mulitmethods?
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.
What is this screenshot from? Looks neat.
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
so
instead of
(-> current-state
(update-in [matchWinner :score] inc)
...)
(defn increment-score-for [game-state player]
(update-in game-state [player :score] inc))
and
(-> current-state
(increment-score-for matchWinner))
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?
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?
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?
@gr.evocatus 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.
See the bottom section of https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows
Also, if you have any questions about the CLI tools on Windows, or you get stuck, there's a #clj-on-windows channel.
@borkdude 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.
See https://blog.michielborkent.nl/2020/07/26/remote-wsl2-clojure/
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.
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.
@gr.evocatus I would read this: https://code.visualstudio.com/docs/remote/containers#:~:text=The%20Visual%20Studio%20Code%20Remote,Studio%20Code's%20full%20feature%20set.
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
Ah, gotcha!
@gr.evocatus 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
(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 <https://scoop.sh/>
:
> Set-ExecutionPolicy RemoteSigned -scope CurrentUser
@seancorfield 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.
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))?
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.
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])
@codonnell no, the point, if understand it correctly, is to apply (f1 x)
to (f2 y)
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
On the other hand, Wikipedia says https://en.wikipedia.org/wiki/Cartesian_product#Cartesian_product_of_functions
Then the map
answer should do the trick, indeed
(map #(%1 %2) [f g] [x y])
, I guess