0

Super beginner question here. I'm following the (good) book Programming Clojure, and chapter 5 is about coding a small Snake game. Utility code is provided, and I decided to follow it by starting a new Leiningen project (lein new app snake). In my src/snake/core.clj I'd like to :use a file named import_static.clj written by the authors. I copied the file into src/snake, and in src/snake/core.clj I copied from the samples the import line (:use snake.import-static). But when I evalute the whole file in the REPL I have this error : "FileNotFoundException Could not locate import_static__init.class or import_static.clj on classpath".

Using Clojure 1.5.1, both in the project.clj file and the editor's REPL (SublimeText + plugin SublimeREPL). The directory structure :

src/
  snake/
    core.clj
    import_static.clj

Top of core.clj :

(ns snake.core
    (:import (java.awt Color Dimension)
       (javax.swing JPanel JFrame Timer JOptionPane)
           (java.awt.event ActionListener KeyListener))
  (:gen-class)
  (:use snake.import-static))

Top of import_static.clj :

(ns ^{:author "Stuart Sierra",
      :doc "Import static Java methods/fields into Clojure"}
  snake.import-static
  (:use clojure.set))

I tried removing the snake from both the :use call and the namespace declaration, with no luck. Can you help me ? Note that I have no knowledge of the JVM, and it may be the classpath or my editor.

DjebbZ
  • 1,594
  • 1
  • 18
  • 34

1 Answers1

0

I just found out, and thought I would share the answer with everyone.

It had nothing to do with the code, but my editor's REPL. Lein's REPL was ok as I could run lein run and lein repl and see the prompt being set to the namespace snake.core=>, whereas in SublimeText's SublimeREPL's REPL it was set to user.core=>. I just had to close it, open the project.clj file and from here open launch a Clojure REPL with SublimeREPL. It is now set properly to snake.core=> and no more error.

Back to coding !

DjebbZ
  • 1,594
  • 1
  • 18
  • 34
  • 1
    It is expected that a repl to put you into the user ns when you start it (though not user.core, I have never seen that). You can switch to an ns as follows `(in-ns 'snake.core)`, after requiring the file that defines it. – noisesmith Dec 02 '13 at 15:50
  • Didn't know about the `in-ns` function, thanks for the pointer. – DjebbZ Dec 03 '13 at 13:40