(clj 3) Clojure's 'and' and 'or' are weird (but not really)

Early in chapter 3 of the Brave and True-book the Boolean operators and and or are introduced:

Clojure uses the Boolean operators or and and. or returns either the first truthy value or the last value. and returns the first falsey value or, if no values are falsey, the last truthy value.

This explanation is followed by some examples:

(or false nil :large_I_mean_venti :why_cant_I_just_say_large)
; => :large_I_mean_venti

(or (= 0 1) (= "yes" "no"))
; => false

(or nil)
; => nil
(and :free_wifi :hot_coffee)
; => :hot_coffee

(and :feelin_super_cool nil false)
; => nil

What I found remarkable about this is that and and or do not return a boolean in all cases. Before I go into that, let's back up a second and cover their basics in a little more depth first.

Read more…

(clj 2) Setting up Vim for Clojure

As mentioned in my previous post I've decided to use Vim as my Clojure editor. That leaves me with three things to do: getting reacquainted with Vim, updating my Vim config in the .vimrc file, and installing both general and Clojure-specific Vim plugins.

Getting reacquainted with Vim

Ever since I learned Vim basics a long time ago I have been using it once in a while to make small edits to a config file or a commit message, but not for anything more complicated than that. So that's the first thing I wanted to address: refresh my basics and make sure I know where to find more information when I need it.


I figured that a good way to get back into Vim was the Vimtutor. It's a 30-minute interactive tutorial where you edit a file with instructions with vim. I kept notes of what it covers, which you can find here. Vim's help also includes a quickref, an "Overview of the most common commands you will use", which is intimidatingly long considering that description. As a reference to look things up in, it should be useful, though.

Read more…

(clj 1) Deciding on a Clojure editor

The second chapter of "Clojure for the Brave and True" is all about Emacs, "an excellent Clojure editor". Now you might wonder: does your choice of editor really matter that much? You're learning the language, so you don't need advanced IDE features. Some syntax highlighting, some code completion, something to help you manage all those parantheses perhaps, done. That would be true if not for the Clojure REPL.

The Clojure REPL

The REPL is definitely a Thing™️ in Clojure. It gives you a prompt where you can type code and it will execute it immediately. You can also load files with code into it, interacting with the functions and data defined in those. So that's a signifcantly faster feedback loop than having to compile and then run - which is how you'd normally run something written in Clojure, since its primary platform is the JVM. There are different ways of launching a REPL, but most guides I found tell you to use Leiningen. Oh, and REPL stands for Read-Evaluate-Print_Loop, because that's what the REPL does.

It definitely feels like this REPL is a bigger deal than I appreciate right now. Probably because I have only just begun learning Clojure. On the other hand, I may have also been spoiled by the quick feedback provided by Python and its IDLE. On the third hand, it's only because of learning of the Clojure REPL, I looked into importing files into Python's IDLE and found out that's indeed a thing it can do.

Read more…

(clj 0) Diving straight in with some koans

Why Clojure?

A long time ago (meaning I don't remember when but it's been a while) I learned about a programming language called Lisp. It was said that by studying this language you'd gain deep insights into programming and you'd never write code the same way again. That definitely piqued my interest.

Some time later (don't remember when exactly either) I learned about the existence of Clojure and that it too, was something special. So I added it to the list of programming languages I wanted to learn some day.

Then, earlier this month, I felt the need to start a new project. To learn something new. So I figured I'd learn Lisp. That didn't last long though, as I found out that the recommended editor for Lisp is Emacs. And from trying out Emacs and vi about 20 years ago I knew that for some reason vi does fit with how my mind works, and Emacs doesn't.

Read more…