clojure

Why doesn't (apply or [true false]) work in Clojure?

From what I understand about apply, it unpacks a list and turns the elements into arguments for a function. I see that (apply + [1 2 3]) works as expected, i.e: it's equivalent to (+ 1 2 3). Why then is (apply or [true false]) invalid? Isn't it equivalent to (or true false) ? ...

Profiling tool for Clojure?

Hi, does anyone know of a good profiling tool or library for Clojure? I would prefer something that could be used from the REPL, along the lines of (with-profiling ...) in Allegro Common Lisp back in the day. Is there anything along those lines? Or do you have any experience with (non-commercial) Java profilers that work well with C...

How to install clojure-contrib on Windows?

I can't seem to find a way to launch the Clojure REPL with the contrib library included. If I understood the documentation correctly then this command should do it: C:\clojure-1.1.0>"%ProgramFiles%\Java\jre6\bin\java.exe" -cp clojure.jar:clojure -contrib.jar clojure.main Exception in thread "main" java.lang.NoClassDefFoundError: clojure...

Why does dotrace throw a StackOverflowError here?

(use '[clojure.contrib.trace]) (dotrace [str] (reduce str [\a \b])) ...

Defining Clojure macro syntax

I defined an unless macro as follows: user=> (defmacro unless [expr body] (list 'if expr nil body)) #'user/unless user=> (unless (= 1 2) (println "Yo")) Yo As you can see it works fine. Now, in Clojure a list can be defined in two ways: ; create a list (list 1 2 3) ; shorter notation '(1 2 3) This means that the unless macro can ...

Chain call in clojure?

I'm trying to implement sieve of Eratosthenes in Clojure. One approach I would like to test is this: Get range (2 3 4 5 6 ... N) For 2 <= i <= N Pass my range through filter that removes multiplies of i For i+1th iteration, use result of the previous filtering I know I could do it with loop/recur, but this is causing stack overflow...

Clojure - tail recursive sieve of Eratosthenes

I have this implementation of the sieve of Eratosthenes in Clojure: (defn sieve [n] (loop [last-tried 2 sift (range 2 (inc n))] (if (or (nil? last-tried) (> last-tried n)) sift (let [filtered (filter #(or (= % last-tried) (< 0 (rem % last-tried))) sift)] (let [next-to-try (first (filter #(> % last-tried) ...

Efficient Clojure workflow?

I am developing a pet project with Clojure, but wonder if I can speed up my workflow a bit. My current workflow (with Compojure) is: Start Swank with lein swank. Go to Emacs, connect with M-x slime-connect. Load all existing source files one by one. This also starts a Jetty server and an application. Write some code in REPL. When sati...

xcode scripting language

i notice that Java has a number of ancillary scripting languages. Clojure and Groovy for example. My understanding is that these can be used when the full might and power of Java does not need to be applied and a speedy cludge can be hacked in Groovy/Clojure. But at the end of the day the scripting tools contribution gets compiled into t...

Clojure: Avoiding stack overflow in Sieve of Erathosthene?

Here's my implementation of Sieve of Erathosthene in Clojure (based on SICP lesson on streams): (defn nats-from [n] (iterate inc n)) (defn divide? [p q] (zero? (rem q p))) (defn sieve [stream] (lazy-seq (cons (first stream) (sieve (remove #(divide? (first stream) %) (rest stream)))))) (def primes (si...

Scala - Java = ? (Or Clojure - Java = ?)

Is it possible for a developer to use Scala without knowing Java? Is it possible for a developer to use Clojure without knowing Java? Note: For example I am a C# developer and I use .NET without knowing any VB (Of-course WF 4.0 uses VB for statements, so I refuse any projects involving WF 4.0 :) ). Summary I: Thanks to all for your a...

Is there any problem with namespacing clojure keywords in a non-existent namespace?

Should I feel wary about creating clojure keywords which have non-existent namespaces? An example would be :foo/bar, where namespace foo doesn't actually exist. This seems to be possible because these keywords behave like literals. I couldn't find any problems doing this in the REPL, but I'm concerned about possible problems with A...

In Clojure - How do I access keys in a vector of structs

I have the following vector of structs: (defstruct #^{:doc "Basic structure for book information."} book :title :authors :price) (def #^{:doc "The top ten Amazon best sellers on 16 Mar 2010."} best-sellers [(struct book "The Big Short" ["Michael Lewis"] 15.09) (struct book "The Help"...

Can I program for android using any JVM language?

Can I use other JVM languages besides Java (e.g. jruby, jython, clojure) to program for android, or is it java only? There was a similar question asked over a year ago but I wasn't sure if there'd been any change since then. ...

Clojure: seq (cons) vs. list (conj)

I know that cons returns a seq and conj returns a collection. I also know that conj "adds" the item to the optimal end of the collection, and cons always "adds" the item to the front. This example illustrates both of these points: user=> (conj [1 2 3] 4) //returns a collection [1 2 3 4] user=> (cons 4 [1 2 3]) //returns a seq (4 1 2 3...

Installing Enclosure with Netbeans

Hi all, I am having trouble installing Enclosure and getting it to work. I have followed this guide http://www.enclojure.org/gettingstarted and successfully installed Enclosure (I think). However, when I try to build the sample application (labrepl) I get a bunch of errors and a failed build. I haven't used Java in a long time and I'v...

Lazy Sequences that "Look Ahead" for Project Euler Problem 14

I'm trying to solve Project Euler Problem 14 in a lazy way. Unfortunately, I may be trying to do the impossible: create a lazy sequence that is both lazy, yet also somehow 'looks ahead' for values it hasn't computed yet. The non-lazy version I wrote to test correctness was: (defn chain-length [num] (loop [len 1 n num] (con...

When and how should independent hierarchies be used in clojure?

Clojure's system for creating an ad hoc hierarchy of keywords is familiar to most people who have spent a bit of time with the language. For example, most demos and presentations of the language include examples such as (derive ::child ::parent) and they go on to show how this can be used for multi-method dispatch. In all of the sli...

Overriding equals, hashCode and toString in a Clojure deftype

I'm trying to create a new type in Clojure using deftype to implement a two dimensional (x,y) coordinate, which implements a "Location" protocol. I'd also like to have this implement the standard Java equals, hashCode and toString methods. My initial attempt is: (defprotocol Location (get-x [p]) (get-y [p]) (add [p q...

Type hinting for functions in Clojure

I'm trying to resolve a reflection warning in Clojure that seems to result from the lack of type inference on function return values that are normal Java objects. Trivial example code that demonstrates the issue: (set! *warn-on-reflection* true) (defn foo [#^Integer x] (+ 3 x)) (.equals (foo 2) (foo 2)) => Reflection warning, NO...