I've started working on a chess game in Clojure, but am having trouble with my namespace. At the top of my file, I have
(ns chess.core
(:require clojure.contrib.str-utils2))
and also define several functions, including to-string
, which turns the symbol for a game piece into a string. However, when I compile:
core.clj:21:8:
error: java.lang.Exception: Unable to resolve symbol: to-string in this context (core.clj:21)
I've done some experimenting, and discovered that I get an error the first time I call a function that I defined myself. I've also discovered that I usually don't get an error if I comment out the ns
call. Sometimes it can be fixed by restarting the Swank server (and sometimes it can't). For a while I just had (ns chess.core)
, which threw the same error, so I commented it out and continued hacking. But now I need to upper-case something, so I need str-utils.
Speaking about str-utils, I use Leiningen, and have the following in project.clj
under :dependencies
:
[org.clojars.jhowarth/clojure-contrib "1.2.0-RC3"]]
; [clojure.contrib.str-utils2 "1.2.1"]]
The top one works, the bottom one doesn't.
So I feel like I'm just ignorant about how Clojure namespacing and libraries work, but at the same time everyone else seems to be using (ns foo.bar)
successfully.