clojure

help with running clojure, possible classpath issue

admin@apollo:~/clojure$ clojure Clojure 1.0.0- user=> (require 'clojure.contrib.str-utils) java.io.FileNotFoundException: Could not locate clojure/contrib/str_utils__init.class or clojure/contrib/str_utils.clj on classpath: (NO_SOURCE_FILE:0) user=> What have I done wrong while installing clojure? Why cant clojure locate my java clas...

Clojure failing to print non-ASCII chars on OS X

I've installed Clojure 1.2.0 using Homebrew package management system on Mac OS X 10.6.4. Running: $ clj -e '(println "русский язык\n")' in the Terminal results in: ??????? ???? While running in the same terminal: $ php -r 'echo "русский язык\n";' displays the Cyrillic text correctly. The same effect when running $ clj <some .c...

clojure pmap/preduce vs fork-join

Looks like clojure will have a fork-join implementation which looks like a functional wrapper over java's fork join framework. I am wondering what the difference between these and pmap/preduce could be ? ...

How to remove duplicated value in list on clojure?

hello I wanna remove duplicated value in list on clojure? for example) from ("a" "b" "c" "a") to ("a" "b" "c") ...

What's your reason to learn clojure ?

I got a personal question for you guys out there: what's your reason for learning Clojure ? (For me, it's the same thing as it was with Java over C, it promises a better programming experience) ...

How do I get core clojure functions to work with my defrecords

I have a defrecord called a bag. It behaves like a list of item to count. This is sometimes called a frequency or a census. I want to be able to do the following (def b (bag/create [:k 1 :k2 3]) (keys bag) => (:k :k1) I tried the following: (defrecord MapBag [state] ...

Does "The whole language always available" hold in case of Clojure?

Ninth bullet point in Paul Graham's What Made Lisp Different says, 9. The whole language always available. There is no real distinction between read-time, compile-time, and runtime. You can compile or run code while reading, read or run code while compiling, and read or compile code at runtime. Running code at read-time le...

The more threads that changes the Clojure's ref are, the more does the rate of retries per threads rise?

I worry about this a little. Imagine the simplest version controll way that programmers just copy all directory from the master repository and after changing a file do reversely if the master repository is still the same. If it has been changed by another, they must try again. When the number of programmers increases, it is natural tha...

what is the parameter to ns ?

what is the parameter to ns ? the documentation says something, but it's not clear (to me, at least) my-new-namespace=> (doc ns) ------------------------- clojure.core/ns ([name docstring? attr-map? references*]) Macro Sets *ns* to the namespace named by name (unevaluated), creating it if needed. ...the rest of the documentatio...

clojure swank server opens public port?

(This question has been downvoted, which I find strange. How have I offended?) Am I right to think that running a swank server usually opens port 4005 to the world, not bound to localhost-only connections? So anyone hacking in a café is not only allowing passers-by to execute arbitrary code on their computer, but is giving them a nice ...

putting clojure code in a loop

(def throws 10) (defn r-squared [x y] (+ (* (- 0.5 x) (- 0.5 x)) (* (- 0.5 y) (- 0.5 y)))) (loop [hits 0] (let [x (rand) y (rand)] ; still inside the let (if (< (r-squared x y) 0.25) ;is it a hit or not? if not, try again (recur (inc hits)) (* 4 (/ hits throws))))) I got that code working a...

Clojure: creating new instance from String class name

In Clojure, given a class name as a string, I need to create a new instance of the class. In other words, how would I implement new-instance-from-class-name in (def my-class-name "org.myorg.pkg.Foo") ; calls constructor of org.myorg.pkg.Foo with arguments 1, 2 and 3 (new-instance-from-class-name my-class-name 1 2 3) I am looking fo...

How could we create "instances" of a type or record on the fly

This question is closely related to this one but i think is more general. Recently i try to create type "instances" on the fly with multimethods (or with a unique function constructor if possible), based in a metadata tag. I linked a type (a java class under the hood) with this tag and then i didnt know how to continue in a elegant way ...

Thread Safe Object Pool with Guarantee of Returning Existing Object if Strong References Exist?

I'm trying to extend the Clojure language to extend ACI-guaranteed refs to ACID-guaranteed drefs (durable refs). The API is to simply to call (dref key value), where key is a String of the key to be used in the underlying data store (BDB JE in my current implementation), and value is the Object that the dref should be initialized to. I...

JVM options using Leiningen

How do I set options like -server when I launch Clojure using lein swank? ...

How to use my own versions of Clojure libraries?

Say I made a change to a Clojure library (eg. added a parameter to the request-token in clj-oauth) and want to use that changed library in my project. What's the best way to do this, short of compiling the new library as a JAR and copying that to my project lib? I want to be able to tweak the library and my project at the same time (pre...

Clojure-problem using javax.sound.midi.Sequencer

I'm trying to use some Java-classes with Clojure. I've tried it with Scala with success, but with Clojure, I get an IllegalArgumentException. Here's the API: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/reflect/Method.html The code below: (import '(javax.sound.midi MidiSystem Sequencer Sequence)) (def mySequencer (MidiSy...

Generating Random Numbers in Incanter

How do I use the random number generators in Parallel Colt from incanter? I've listed these dependencies in my project.clj file: :dependencies [[org.clojure/clojure "1.2.0"] [org.clojure/clojure-contrib "1.2.0"] [incanter/core "1.2.3"] [incanter/parallelcolt "0.9.4"]] And then I tried...

Clojure: fully qualified name of a function

In Clojure, is there a more elegant way of finding the fully qualified name of a function (known to have meta info) than (defn fully-qualified-name [fn] (let [fn-meta (meta fn ) fn-ns (ns-name (:ns fn-meta)) ] (str fn-ns "/" (:name fn-meta)))) A run-time solution is required. Read-time and compile-time solutions ...

How do I write a Clojure macro to create more than one expression?

Is it possible to write a macro in Clojure that generate more than one value or expression? For me it looks like it's not possible, at least not by using the syntax quote template `(..). e.g. from: [1 4] via [1 (mr 2 3) 4] to [1 2 3 4] or from: (do (prn 1) (prn 4)) via: (do (prn 1) (mr 2 3) (prn 4)) to: (do (prn 1) ...