clojure

Clojure Matrix Representation

What is a good representation for matrices in Clojure? I'm interested in dealing with dense matrices of floating point numbers. The "list of lists" representation springs to mind, but is there something better? Some criteria for a good representation include: Efficiency: They won't be used for constant processing of huge data sets, bu...

Enclojure REPL can't find dependent clj file on Load

I have a problem with the Enclojure REPL and using clojure modules from it. The Load/Change REPL to file/ns works fine with an isolated clojure file, but breaks with a file which has references to another clojure file which I try to use from my project. Here are the exact steps: Create a new project. Create a clojure module foobar.cl...

Mapping a function on the values of a map in Clojure

I want to transform one map of values to another map with the same keys but with a function applied to the values. I would think there was a function for doing this in the clojure api, but I have been unable to find it. Here's an example implementation of what I'm looking for (defn map-function-on-map-vals [m f] (reduce (fn [altered...

interaction between seque and pmap

If I pmap a function onto a sequence how far ahead will the sequence be realised in parallel If I have a single thread reading from a sequence being produced in parallel? will this be different if I wrap it in a seque: (seque 30 (pmap do-stuff (range 30000))) vs. (pmap do-stuff (range 30000)) ...

clojure (with-timeout ... macro)

I'm looking for a macro that will throw an exception if an expression takes longer than X seconds to complete. ...

How can I convert a LazySeq of Characters to a String in Clojure?

Let's say I have a LazySeq of java.lang.Character like (\b \ \! \/ \b \ \% \1 \9 \/ \. \i \% \$ \i \space \^@) How can I convert this to a String? I've tried the obvious (String. my-char-seq) but it throws java.lang.IllegalArgumentException: No matching ctor found for class java.lang.String (NO_SOURCE_FILE:0) [Thrown class clojure...

Reduce a set of functions over a value?

Hi, I'm looking for a clean, idiomatic way to do a "backwards reduce" in Clojure. I've got (def fns '(fn1 fn2 fn3)) (def val 42) I'd like to obtain (fn3 (fn2 (fn1 val))), and I'm not picky about the order. So I'd like to consecutively apply a sequence of functions to a value, rather than consecutively a sequence of values to a fu...

How can I use the Clojure REPL together with Qt Jambi?

I have not found a solution to use the Clojure REPL with Qt on the web. Basically the problem is that the REPL hangs as soon as you call QApplication/exec in order to get the UI to display. You cannot C-c C-c back into the REPL, and closing the active Qt window seems to kill the whole Clojure process. Now simply calling QApplication/pro...

Clojure: How to find out the arity of function at runtime ?

Given a function object or name, how can I determine its arity? Something like (arity func-name) . I hope there is a way, since arity is pretty central in Clojure ...

How can I use Clojure's distinct? function on a collection?

The Clojure distinct? method doesn't take a collection, but rather a list of args (distinct? x) (distinct? x y) (distinct? x y & more) So (distinct? 0 0 0 0) correctly returns false, while (distinct? [0 0 0 0]) returns true. How can I use distinct? on a collection so that passing it a collection [0 0 0 0] would return false since the ...

Aliasing a java package name in clojure

Given a java package x.y.z, can I alias x.y.z to a shorter name, so that i can then refer to java classes inside the package as my-alias.MyJavaClass. If that isn't possible, I could just import all classes into my namespace, but I don't want to specify the names of each class manually, and the clojure API docs doesn't seem clear on whet...

how to efficiently apply a medium-weight function in parallel

I'm looking to map a modestly-expensive function onto a large lazy seq in parallel. pmap is great but i'm loosing to much to context switching. I think I need to increase the size of the chunk of work thats passed to each thread. I wrote on a function to break the seq into chunks and pmap the function onto each chunk and recombine them...

Whats wrong with this Clojure program?

I recently started reading Paul Grahams 'On Lisp', and learning learning clojure along with it, so there's probably some really obvious error in here, but I can't see it: (its a project euler problem, obviously) (ns net.projecteuler.problem31) (def paths (ref #{})) ; apply fun to all elements of coll for which pred-fun returns true (d...

Dynamic method calls in a Clojure macro?

I'm attempting to write a macro which will call java setter methods based on the arguments given to it. So, for example: (my-macro login-as-fred {"Username" "fred" "Password" "wilma"}) might expand to something like the following: (doto (new MyClass) (.setUsername "fred") (.setPassword "wilma")) How would you recommend tacklin...

taking java method names as function arg in clojure

All, I want to create a function that takes a symbol representing a java method and applies it to some object: (user=> (defn f [m] (. "foo" (m))) When I execute this, I get a result much different from what I expect user=> (f 'getClass) java.lang.IllegalArgumentException: No matching method found: m for class java.lang.String (NO_SO...

Is functional Clojure or imperative Groovy more readable?

OK, no cheating now. No, really, take a minute or two and try this out. What does "positions" do? Edit: simplified according to cgrand's suggestion. (defn redux [[current next] flag] [(if flag current next) (inc next)]) (defn positions [coll] (map first (reductions redux [1 2] (map = coll (rest coll))))) Now, how about this vers...

Server programming with Clojure

How to implement 10k connections echo server in Clojure? clojure.contrib.server-socket is not the answer since it crates a new OS thread for every connection. ...

Help translating this Java codeblock to Clojure?

I'm getting my feet wet with Clojure, and trying to get used to functional programming. I've been translating various imperative functions from other languages into their Clojure equivalents -- and so far everything has been going well. However, I've now run into a sticking point and I have no idea how to translate this Java method int...

clojure rmi classpath problem

Hi, I am trying to use clojure to implement a "plugin" for some vendor supplied software. Here is a little background on the vendor supplied software. It expects me to implement a particular interface and then put the jar file containing that implementation into a directory on its server. Then when a client runs the software, my imple...

Newbie transforming CSV files in Clojure

I'm both new and old to programming -- mostly I just write a lot of small Perl scripts at work. Clojure came out just when I wanted to learn Lisp, so I'm trying to learn Clojure without knowing Java either. It's tough, but it's been fun so far. I've seen several examples of similar problems to mine, but nothing that quite maps to my pro...