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...
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...
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...
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))
...
I'm looking for a macro that will throw an exception if an expression takes longer than X seconds to complete.
...
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...
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...
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...
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
...
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 ...
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...
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...
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...
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...
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...
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...
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.
...
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...
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...
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...