JetBrains / la-clojure

Clojure plugin for IntelliJ IDEA
Apache License 2.0
220 stars 49 forks source link

Cannot load .clj file into REPL #2

Closed acgetchell closed 12 years ago

acgetchell commented 12 years ago

Tools->Clojure REPL->Load file to REPL (and all other options) greyed out.

ghoshCoder commented 12 years ago

This should work if you put your cursor in the clojure code window.

acgetchell commented 12 years ago

I realized that I had to start the Clojure REPL first, then this works as you stated.

acgetchell commented 12 years ago

Actually, it doesn't really work, as seen below:

user=> (load-file "C:/Projects/ProjectEuler/src/ProjectEuler/scratch.clj")

'ProjectEuler.scratch/qsort

user=> (qsort [2 1 4 3]) java.lang.Exception: Unable to resolve symbol: qsort in this context (NO_SOURCE_FILE:2)

Whereas, cutting and pasting the code into the console:

user=> (ns ProjectEuler.scratch)

(defn nom [n](take n %28repeatedly #%28rand-int n%29%29))

(defn sort-parts "Lazy, tail-recursive, incremental quicksort. Works against and creates partitions based on the pivot, defined as 'work'." [work](lazy-seq %28loop [[part & parts] work] %28if-let [[pivot & xs] %28seq part%29] %28let [smaller? #%28< % pivot%29] %28recur %28list* %28filter smaller? xs%29 pivot %28remove smaller? xs%29 parts%29%29%29 %28when-let [[x & parts] parts] %28cons x %28sort-parts parts%29%29%29%29%29))

(defn qsort [xs](sort-parts %28list xs%29)) nil ProjectEuler.scratch=> ProjectEuler.scratch=> #'ProjectEuler.scratch/nom ProjectEuler.scratch=>#'ProjectEuler.scratch/sort-parts ProjectEuler.scratch=> ProjectEuler.scratch=> #'ProjectEuler.scratch/qsort ProjectEuler.scratch=> (qsort [2 1 4 3]) (1 2 3 4)

This example code taken from Chapter 6 of "The Joy of Clojure"

ghoshCoder commented 12 years ago

I see that your namespace is ProjectEuler.scratch. So if you try to use the repl to call this function first switch to that namespace using (in-ns 'ProjectEuler.scratch)

acgetchell commented 12 years ago

Of course, how silly of me. Thank you!