scribble

Corey Purcell

About Email GitHub Resume

07 Feb 2015
Clojure Unbound Function in Vim-Fireplace

While working through Programming Clojure, I was attempting to build a move function. After I attempted to load the code in my repl with Vim Fireplaces' cpr I kept getting an error when trying to call my move function (move (create-snake)).

Attempting to call unbound fn: #'reader.snake/move

It turns out that the code wasn’t comiling. The clue was that the error means you are trying to call a function that was declared but not defined.

(declare foo)
(foo)
;java.lang.IllegalStateException: Attempting to call unbound fn: #'user/foo
 
(defn foo [] "OK")
(foo)
"OK"

Here was my original code:

(defn move [{:keys [body dir] :as snake} & grow]
  (assoc snake :body (cons (add-points (first body) dir)
                           if grow body (butlast body))))

Trying to compile with vim-fireplace cpp

java.lang.RuntimeException: Unable to resolve symbol: if in this context, compiling:(reader/snake.clj:40:22)

Clojure devs will probably see that I’m missing the () around my “if” form. Here’s the correct code:

(defn move [{:keys [body dir] :as snake} & grow]
  (assoc snake :body (cons (add-points (first body) dir)
                           (if grow body (butlast body)))))

It was a strang error for a person new to clojure just trying to make it through the book.


Til next time,

scribble

About Email GitHub Resume