clojure

How do I pass a static method to comp in clojure?

It seems as though I'm having problems accessing Integer.parseInt in comp. I can access it normally like this: user=> (Integer/parseInt "123") 123 But if I put it in comp, I get an error: user=> (def vect-to-int (comp Integer/parseInt (partial apply str))) java.lang.Exception: Unable to find static field: parseInt in class java.lang...

Thinking in Lazy Sequences

Hello, Taking an example of Fibonacci Series from the Clojure Wiki, the Clojure code is : (def fib-seq (lazy-cat [0 1] (map + (rest fib-seq) fib-seq))) If you were to think about this starting from the [0 1], how does it work ? Would be great if there are suggestions on the thought process that goes into thinking in these terms. ...

Holding onto the head of a sequence

Reading a recent question I identified the function being discussed (def fib-seq (lazy-cat [0 1] (map + (rest fib-seq) fib-seq))) as holding onto the head of a sequence, but it occurred to me re-reading my answer that I had glossed over the details like they were obvious, so I went back to clarify and came up short. I know that fi...

How to use a compiled Clojure class in Eclipse with Counterclockwise

I created a basic hello world class in eclipse with clojure and counterclockwise and I'm able to compile it with clojure no problem. (ns ca.ckovacs.test.helloWorld (:gen-class)) (defn -main [greetee] (println (str "Hello " greetee "!"))) I see that this generates three classes in my /classes folder: helloWorld__init.class...

how to wait for a process to end in java or clojure

How can I be notified when a process I did not start ends and is their a way to recover its exit code and or output? the process doing the watching will be running as root/administrator. ...

What are common conventions for using namespaces in Clojure?

I'm having trouble finding good advice and common practices for the use of namespaces in Clojure. I realize that namespaces are not the same as Java packages so I'm trying to tease out the conventions in Clojure, which seem surprisingly hard to determine. I think I have a pretty good idea how to split functions into clj files and eve...

Do the Clojure Inspector (inspect) ui buttons do anything?

Clojure comes with some basic ui apps that let you inspect objects. The generic "inspect" ui has buttons on the top for List, Table, Bean, Line, Bar, Prev, Next, etc but as far as I can tell they don't do anything. I looked at the source and they seem functionless from the code as far as I can tell. Am I crazy? (use 'clojure.inspecto...

Compile Clojure?

I am new to clojure and I have tried to compile it last night but I couldn't seem to do it and I have no idea. I am on windows and don't know much about java. I just want a stand-alone file that I can give to my friends. (I know they need java) Can anyone help? ...

How do I determine if a character is within a range in Clojure?

I'm trying to write a function that checks if a character is within a certain hexadecimal range. I'm trying the code shown below: (def current \s) (and (>= current (char 0x20)) (<= current (char 0xD7FF))) I get the following error: java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Number (NO_SOURCE_FILE...

In Clojure how could I create an "add id to map" function?

Say I have a collection of maps: (def coll #{{:name "foo"} {:name "bar"}}) I want a function that will add an id (a unique number is fine) to each map element in the collection. i.e. #{{:id 1 :name "foo"} {:id 2 :name "bar"}} The following DOES NOT WORK, but it's the line of thinking I currently have. (defn add-unique-id [coll] (m...

When should one use the temporarily-rebind-a-special-var idiom in Clojure?

I've noticed that some libraries such as clojure-twitter use special vars (the ones intended for dynamic binding that are surrounded by asterisks) for oauth authentication. You save your authentication in a var and then use (with-oauth myauth ..). I think this is a very nice solution to this sort of problem, because you can rebind the au...

Java in Clojure, Evaluation question

Hi, Is there a detailed explanation for results obtained on evaluating the following on REPL. (.PI Math) gives IllegalArgument Exception while (. Math PI) evaluates to 3.141592653589793 ...

How to write self-documenting code in Clojure/any other lisp

I'm used to Java code, with its long descriptive names, and with lots of temporary variables used only to give a name to some return value. This kind of code is very easy to understand even after a year break. When using Lisp, however, I can't understand things like "what is in the 3rd position of this list" the next day, or even next h...

A gentle tutorial to Emacs/Swank/Paredit for Clojure

I am moving to Emacs to work on Clojure/Lisp. What is all the information I need to setup on Emacs to be able to do the following? automatic matching/generation of corresponding closing brackets autoindent Lisp/Clojure style, not C++/Java style Syntax highlighting Invoking REPL To be able to load a part of code from file into the REPL ...

How does one know when to newline in Clojure/Lisp in general?

Here is a bit of example code: (deftype Deck52 [suits] :as this DeckOfCards (check-empty [] (Deck52. (apply hash-map (apply concat (remove (-> nil?) (for [[key val] suits] (if (emp...

Clojure: How to pass two sets of unbounded parameters?

Contrived example to illustrate: (def nest1 {:a {:b {:c "foo"}}}) (def nest2 {:d {:e "bar"}}) If I wanted to conj these nests at arbitrary levels, I could explicitly do this: (conj (-> nest1 :a :b) (-> nest2 :d)) ; yields {:e "bar", :c "foo"} (conj (-> nest1 :a) (-> nest2 :d)) ; yields {:e "bar", :b {:c "foo"}} But what if I wante...

Homoiconicity, How does it work ?

Hi, Can someone suggest articles that explain the concept of Homoiconicity, especially using Clojure. Why is it that Clojure is homoiconic but its hard to do that in other languages such as Java ? ...

Using quote in Clojure

Hi, Quoting in clojure results in non-evaluation. ':a and :a return the same result. What is the difference between ':a and :a ? One is not evaluated and other evaluates to itself... but is this same as non-evaluation ? ...

Can I get a this variable in a def?

Hi! Is there a way to mimic a this variable in something like (def foo {:two 2 :three (inc (:two this))})? Even better would be something like (def foo {:two 2 :three (inc ::two)}). I was told that there is a library that does exactly this, but I can't really find anything similar. Thanks! ...

NoClassDefFoundError while importing a class with an inner class

Hi! I'm not being able to import a particular class (FinanceService) from a jar. All the others work fine, including the inner-class FinanceService$Versions. I'm getting a NoClassDefFound exception, and I'm not sure how to proceed. This exception occurs, paraphrasing an answer I've found here, when the source was successfully compiled,...