---
date: "2023-06-06T20:11:00.000Z"
title: "2023-06-06"
tags: ["clojure","exercism"]
draft: false
---

I did a bit more work with Clojure today.
My imperative programming habits are still bleeding through.
The exercise introduced `cond` as a sort of case statement for flow control.
I wrote a simple `cond` statement but was getting a bizarre runtime error:

```clojure
(defn my-fn
  [x]
  (cond
    (x < 0) "negative"
    (x = 0) "zero"
    (x > 0) "positive"
  )
)
```

```sh
user=> (my-fn 1)
Execution error (ClassCastException) at user/my-fn (REPL:4).
class java.lang.Long cannot be cast to class clojure.lang.IFn (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')
```

It took me a frustratingly long time to realize I needed to use prefix notation for the conditions in the `cond`.

```clojure
(defn my-fn
  [x]
  (cond
    (< x 0) "negative"
    (= x 0) "zero"
    (> x 0) "positive"
  )
)
```

```sh
user=> (my-fn 1)
"positive"
```