clojure

Creating Android apps without Java

I'd like to start creating Android apps but I don't like Java. I read that scala can be used to do it. Are there another option?(Clojure?) I'm a Python/Django developer so it would be great to learn a pretty different language. ...

Clojure's protocols influences?

Was Clojure influences by ObjectiveC Protocols? If no then how are they difference? ...

Piping data through arbitrary functions in Clojure

I know that the -> form can be used to pass the results of one function result to another: (f1 (f2 (f3 x))) (-> x f3 f2 f1) ; equivalent to the line above (taken from the excellent Clojure tutorial at ociweb) However this form requires that you know the functions you want to use at design time. I'd like to do the same thing, but at ...

How to pass a typed collection from clojure to java?

I know the basics of clojure/java interop: calling java from clojure and vice versa. However, I was not able to return a typed collection from clojure to java. I am trying to see something of that nature List<TypedObject> from the java code which is calling into clojure. Java Object: public class TypedObject { private OtherType1 _p...

What's a good toString method for a deftype'd object in clojure

(deftype Bag [state] Object (toString [bag] (str "Bag???" state))) I want the toString to look something like clojure.core=> (def b (Bag. {:apples 1 :bannanas 4})) #'clojure.core/b clojure.core=> (str b) "BAG: {:apples 1 :bannanas 4}" What is a nice clojurey way of representing that information? Is "Bag/{:k :v}" ...

How do you use a type outside of its own namespace in clojure?

I have a project set up with leiningen called techne. I created a module called scrub with a type in it called Scrub and a function called foo. techne/scrub.clj: (ns techne.scrub) (deftype Scrub [state] Object (toString [this] (str "SCRUB: " state))) (defn foo [item] (Scrub. "foo") "bar") techne/scrub_test.clj...

How do I map a vector to a map, pushing into it repeated key values?

This is my input data: [[:a 1 2] [:a 3 4] [:a 5 6] [:b \a \b] [:b \c \d] [:b \e \f]] I would like to map this into the following: {:a [[1 2] [3 4] [5 6]] :b [[\a \b] [\c \d] [\e \f]]} This is what I have so far: (defn- build-annotation-map [annotation & m] (let [gff (first annotation) remaining (rest annotation) seq...

Is it possible to create circular references in Clojure ?

Ignoring native interop and transients, is it possible to create any data structures in Clojure that contain direct circular references ? It would seem that immutable data structures can only ever contain references to previous versions of themselves. Are there any Clojure APIs that could create a new data structure that has a reference...

How to force evaluate ?

After playing a while with quote/unquote, I wanted to do a trick, but it didn't want to be done. Here's what I did and what come out : user=> (let [x '#(inc 1)] `(1 ~x)) (1 (fn* [] (inc 1))) But what I wanted was : (1 2) Can you help me do that ? :) And also explain what "part" of Clojure you are using... ...

How does clojure's syntax-quote work?

Various special characters in clojure are abbreviations for things (quote (a b)) is the same as '(a b) as you can see by evaluating: user> ''(a b) (quote (a b)) This seems to be syntax as abbreviation, which strikes me as a fine idea. But the syntax-quote, ` , seems special. I can't think what would be equivalent to `(a b) I wo...

What type is a function ?

let's try some calls to the "type" function : user=> (type 10) java.lang.Integer user=> (type 10.0) java.lang.Double user=> (type :keyword?) clojure.lang.Keyword and now with an anonymous function : user=> (type #(str "wonder" "what" "this" "is")) user$eval7$fn__8 A) what does this mean "user$eval7$fn__8" ? B) and what type is a ...

Simple Yet Compelling Macro Examples which are Not Already in Clojure

Hi, I'm trying to write a macro tutorial, and now I need some examples which are simple to understand, and yet compelling. The problem is that a lot of the obvious things are already in clojure and contrib. And I feel that "look, we can reimplement all the library functions" might not be the best argument for why macros are so great. H...

doto and setting property conditionally

I want to write: (defn download-web-page "Downloads the webpage at the given url and returns its contents." [^String url ^String user ^String password] (with-open [client (doto (WebClient.) (when user (.set_Credentials (NetworkCredential. user password ""))))] (.DownloadString client url))) So I ...

How do I create a "Clojure Application" project in Netbeans 6.9.1

Hi, in Netbeans 6.8 / Enclojure 1.1.3 I have an option for "Clojure Application" when I create a new project. In Netbeans 6.9.1 / Enclojure 1.4(?) this option doesn't appear and instead there is the option of "Clojure Maven". Am I missing something obvious? Is there an option for creating Clojure Application project in 6.9.1? ...

How do I integrate GEVA into Clojure

I am getting into Clojure and Grammatical Evolution at the same time and discovered GEVA, which is a GE tool written in Java. I have no background in Java. So I don't have to re-invent the wheel, how can I integrate GEVA into Clojure? I can execute the default script from the CLI with: java -jar GEVA.jar -main_class Main.Run The ...

Clojure contrib sql makes all numbers a BigDecimal

The clojure.contrib.sql library returns BigDecimals for all numeric fields. What's a good way to have some fields as Integers? Example code below: (sql/with-connection my-db (sql/with-query-results res [sql-str 6722] (into [] res))) In the resulting collection of records all numbers are BigDecimal. Some of these are ...

How to convert a clojure keyword into a string?

In my application I need to convert clojure keyword eg. :var_name into a string "var_name". Any ideas how that could be done? ...

Why does require in the ns form behave different from the require function.

When I require libraries from the ns form I get : test> (ns test (:require '(clojure.contrib [logging :as log] [sql :as sql]) )) lib names inside prefix lists must not contain periods [Thrown class java.lang.Exception] When I use the require function it works as expected. test> (require '(clojure.contrib [logging :as log] [sql :as sq...

How can I type hint an array?

I have the following record: (defrecord Signal [samples ^double sample-rate ^double scaling-factor]) How can I specify samples to be a double array? I am using clojure 1.2.0 Edit: @dreish I get the following output when I call (show Signal) after the changes from levand: [35] <init> (Object,double,double) [36] <init> (Object,doub...

clojure equivalent for ruby's gsub

How do i do this in clojure "text".gsub(/(\d)([ap]m|oclock)\b/, '\1 \2') ...