clojure

Clojure compress vector

I am trying to find a Clojure-idiomatic way to "compress" a vector: (shift-nils-left [:a :b :c :a nil :d nil]) ;=> (true [nil nil :a :b :c :a :d]) (shift-nils-left [nil :a]) ;=> (false [nil :a]) (shift-nils-left [:a nil]) ;=> (true [nil :a]) (shift-nils-left [:a :b]) ;=> (false [:a :b]) In other words, I want to move all of the nil va...

How to run a maven-packaged clojure application from the jar

I have the following contents in src/main/clojure/za/co/pb/maven_test/test.clj file: (ns za.co.pb.maven-test.test (:gen-class)) (defn -main [] (println "Hello world!")) I also have a POM that has the necesary dependencies on clojure-maven-plugin with the compile execution. If I execute a mvn package command, I get a target/maven...

Customizing La Clojure indentation

I must be dense this morning :-). According the the JetBrains La Clojure page, the plugin indentation is customizable. I can't find the customization anywhere. I looked in "File->Settings" everywhere and even did a search for "clojure". Where can I find this? I am running IntelliJ 9.0.3 CE (Build 95.429) with La Clojure 0.2.267 on OS ...

Remove nil values from a map?

I have a Clojure map that may contain values that are nil and I'm trying to write a function to remove them, without much success (I'm new to this). E.g.: (def record {:a 1 :b 2 :c nil}) (merge (for [[k v] record :when (not (nil? v))] {k v})) This results in a sequence of maps, which isn't what I expected from merge: ({:a 1} {:b 2})...

Putting doc-strings on data vars, is it considered idiomatic?

So I have defined some vars to hold state data in my clojure code. I have just discovered I can add a doc-string to those vars e.g.: (def ^{:doc "Documentation for *my-var*"} *my-var*) That lets me call (doc *my-var*) at the REPL. This seems like a valid and useful thing to do but it doesn't seem like common practice in the (...

Can you translate these 2 examples from Functional Languages 101 ? (Scheme -> Clojure)

Got these examples I would like to understand but they are in Scheme. I would like them in Clojure :D Example 1 - counting the length of a list (define length (lambda (ll) (cond ((null? ll) 0) (#t (add1 (length (cdr ll))))))) Exemple 2 - square each element of a list (define squares (lambda (li) (co...

How to transform this simple OOP program to a functional-programming language?

During the last months I have tried to code using the functional programming paradigm. Now I have a solution in OOP and I am trying to find a functional solution. The problem is simple. I have an algorithm, which produces two different arrays as result (a and b). Now, I want to check how good the results are. Therefore I write several ...

Converting a list of lists into a map of lists of lists in Clojure

I have a list of lists and would like to get this into a map where the key is one of the common values in the lists (animal name in this example). I know how to use into {} and for to create a map from a list but this is not exactly what I want. I want the key (animal's name) in the map to refer to a list of lists of these values. I've ...

What are the allowed characters in a Clojure keyword?

I am looking for a list of the allowed characters in a clojure keyword. Specifically I am interested to know if any of the following characters are allowed. "-" "_" "/". [EDIT] I am not a java programmer. So i would not know the underlying ramifications if any. I dont know if the clojure keyword is mapped to a java keyword if there is s...

best way to repeatedly map values from a sequence into an arg list?

Sorry for the noob question, but is there an good way to destructure values from a sequence like this.. (somefunc [[a b c] [1 2 3 4 5 6 7 8 9]] (prn a b c)) ..with the a b c being assigned values until the sequence exhausted and letting me call a function on the args? doseq requires a partition of the right size.. (doseq [[a b c] (pa...

Clojure: gc overhead limit exceeded, lazy evaluation, pi sequence

For the next code: (ns clojure101.series) (defn avg [[x y]] (/ (+ x y) 2)) (defn avg-damp [seq] (map avg (partition 2 seq))) (defn avg-damp-n [n] (apply comp (repeat n avg-damp))) (defn sums [seq] (reductions + seq)) (defn Gregory-Leibniz-n [n] (/ (Math/pow -1 n) (inc (* 2 n)))) (def Gregory-Leibniz-pi (map #(...

What are important languages to learn to understand different approaches and concepts?

When all you have is a pair of bolt cutters and a bottle of vodka, everything looks like the lock on the door of Wolf Blitzer's boathouse. (Replace that with a hammer and a nail if you don't read xkcd) I currently program Clojure, Python, Java and PHP, so I am familiar with the C and LISP syntax as well as the whitespace thing. I know i...

What is the good starting point for Clojure development on Google AppEngine

What is the good starting point for Clojure development on Google AppEngine? Seems like there are two competing libraries appengine-magic and compojure-gae. What is your opinion? ...

How I can eval a buffer and/or an instruction within Emacs with Swank and SLIME?

Hy everyone, I've successfully installed clojure-mode, slime, slime-repl within Emacs. I start a swank server with "lein swank" and hang slime to it with "slime-connect". I can use the SLIME REPL to evaluating Clojure expression within the REPL. How can I eval a single s-exp or a whole file (a.k.a I want to run a Clojure file withing Ema...

Clojure: get list of regex matches

Perhaps I'm going about this all wrong, but I'm trying to get all the matches in a string for a particular regex pattern. I'm using re-matcher to get a Match object, which I pass to re-find, giving me (full-string-match, grouped-text) pairs. How would I get a sequence of all the matches produced by the Match object? In Clojuresque Pytho...

Computer algebra for Clojure

Short version: I am interested in some Clojure code which will allow me to specify the transformations of x (e.g. permutations, rotations) under which the value of a function f(x) is invariant, so that I can efficiently generate a sequence of x's that satisfy r = f(x). Is there some development in computer algebra for Clojure? For (a tri...

Are there any Clojure DSLs ?

Is there any DSL (Domain Specific Language) implemented in Clojure ? ...

Pluggable vector processing units in Clojure

I'm developing some simulation software in Clojure that will need to process lots of vector data (basically originating as offsets into arrays of Java floats, length typically in 10-10000 range). Large numbers of these vectors will need to go through various processing steps - e.g. normalising the vectors, concatenating together two stre...

Which is the most clojuresque way to compare characters and string? (single char string)

Hi to everyone, I was wondering about which is the best (clojuresque) way to compare a character and a string in Clojure. Obviously something like that returns false: (= (first "clojure") "c") because first returns a java.lang.Character and "c" is a single character string. Does exists a construct to compare directly char and string w...

What should I use Clojure's finger trees for?

Clojure's new contrib library group has a finger tree library. What are the use cases for finger trees in clojure? When should finger trees be used instead of one of clojure's other peristent data strucures: vectors, sets, maps, persistentqueues, etc. The Joy of Clojure mentions that Finger trees can be used for indexed collections wh...