user1676605
user1676605

Reputation: 1447

Simple clojure program doesn't work

I am trying to follow the example in Clojure Data Analasys Cookbook. I am using LightTable to play with the program. The first example shows how to read in .csv data.

I used lein new getting-data. I then added the two dependencies to the project file

  (defproject getting-data "0.1.0-SNAPSHOT"

  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [
                  [org.clojure/clojure "1.5.1"]
                  [incanter/incanter-core "1.4.1"]
                  [incanter/incanter-io "1.4.1"]
                ]
  )

Then in the core.clj file I say as below, using cmd-shift-enter in LightTable to evaluate the program, but I get those exceptions:

(use 'incanter.core 'incanter.io)

clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: use in this context, compiling:(/Users/idf/Documents/clojure/getting-data/src/getting_data/core.clj:1:1)

(read-dataset "data/small-sample.csv") 

clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: read-dataset in this context, compiling:(/Users/idf/Documents/clojure/getting-data/src/getting_data/core.clj:4:1)

Not sure what I am doing wrong?

Upvotes: 1

Views: 1144

Answers (2)

fricke
fricke

Reputation: 1400

put your code

(ns getting-data.core)
(use 'incanter.core 'incanter.io)
(read-dataset "data/small-sample.csv") 

in the generated core.clj file move there and press strg-enter. Now it should evaluate everything inside the editor. Alternatively open the project and open an Instarepl and LightTable should ask you into which project the repl should hook into.

regards fricke

Upvotes: 0

amalloy
amalloy

Reputation: 91962

"Unable to resolve symbol: use in this context" means that the light table environment is unable to evaluate basically anything: nothing incanter-related can be the problem. Not using light table, I can't offer further advice on fixing it, but it looks like you've somehow wandered into a namespace that doesn't have clojure.core referred. It should work if you (clojure.core/refer 'clojure.core) before the rest of the code you actually want to run, but of course that's not supposed to be necessary.

Upvotes: 2

Related Questions