Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Anthony Bruno
Anthony Bruno

Posted on • Originally published atanthonybruno.dev on

     

How I’m learning Clojure in 2024

I’ve recently been learning a bit of Clojure and it’s been a lot of fun! I thought I would note down what has been useful for me, so that it might help others as well.

Jumping right in

https://tryclojure.org/ is a great intro to the language. It provides a REPL and a tutorial that takes you through the basic features of Clojure.

Importantly, it forces you to get used to seeing lots of( and)!

Doing exercises

Exercism provides small coding challenges for a bunch of languages, includingClojure. Unlike other platforms (cough leetcodecough), Exercism is focused on learning and I found it a great way to practice writing Clojure.

It provides a code editor and evaluates each challenge when you submit. There’s also a way to submit answers locally from your computer, but I found it quicker just to use the website.

Editor setup

I ended up setting up Neovim for developing locally. This guide was a great inspiration:https://endot.org/2023/05/27/vim-clojure-dev-2023/, although I did end up going with something a little bit simpler.

My .vimrc can be seenherebut probably the most important plugin isConjure, which provides REPL integration in Neovim.

The REPL is one of the big differences compared to programming in other languages. Basically, you start a REPL in the project directory and then you can evaluate code in your editor in that REPL.

This basically gives you really short iteration cycles, you can ‘play’ with your code, run tests, reload code in a running app and all without leaving your editor!

To understand REPL driven development, I really liked thisvideo with teej_dv and lispyclouds. One key thing I learnt was using thecomment function to be able to evaluate code without affecting the rest of my program.

; my super cool function; given a number, adds 2 to it!(defn add-2  [n]  (+ n 2)); This tells Clojure to ignore what comes next; but it still has to be syntactically correct!(comment  (add-2 3) ; <-- I can evaluate this to check my add-2 function :))
Enter fullscreen modeExit fullscreen mode

By opening a REPL and using the Conjure plugin mentioned before I can:

  • ,eb: Evaluate the buffer I am in. Kinda like loading up the file I have opened into the REPL.
  • ,ee: Evaluate the expression my cursor is under.
  • ,tc: Run the test my cursor is over.
  • ,tn: Run all tests in current file.

I use the following alias in my.bash_aliases to easily spin up a REPL:

# From https://github.com/Olical/conjure/wiki/Quick-start:-Clojure# Don't ask me questions about how this works, but it does!alias cljrepl='clj -Sdeps '\''{:deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.42.1"}}}\'\'' \    --main nrepl.cmdline \    --middleware '\''["cider.nrepl/cider-middleware"]'\'' \    --interactive'
Enter fullscreen modeExit fullscreen mode

Docs

For docs, I really likehttps://clojuredocs.org/, which has the docs for the core library. I like the fact that users can submit code examples, which provides better information for each function.

Projects

I’ve currently have 2 projects in Clojure to further my learning.

  1. A bad terminal-based clone(ish) ofBalatro. Balatro is a very addictive deck builder rougelike game. Doing this has been fun and it feels very natural to ‘build up’ over time. The source code can be seenhere.
  2. A application that converts a subreddit into an RSS feed. The idea that this can be a webapp that produces daily RSS feeds for a collection of subreddits.Source code

The End

Thanks for reading!

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
ivangavlik profile image
ivan.gavlik
I've been in programing for 8 years, and I'm still surprised at how much of it is just me talking to my computer.
  • Joined

nice I also started learning Clojure. Language is great

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Australian software engineer. Probably drinking coffee right now.
  • Location
    Australia
  • Joined

More fromAnthony Bruno

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp