Closed acgetchell closed 12 years ago
This should work if you put your cursor in the clojure code window.
I realized that I had to start the Clojure REPL first, then this works as you stated.
Actually, it doesn't really work, as seen below:
user=> (load-file "C:/Projects/ProjectEuler/src/ProjectEuler/scratch.clj")
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"
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)
Of course, how silly of me. Thank you!
Tools->Clojure REPL->Load file to REPL (and all other options) greyed out.