clojure

How to do numerical simulation with immutable data in Clojure?

I'm using Clojure and I need to run a small simulation. I have a vector of length n (n is usually between 10 and 100) that holds values. On each simulation round (maybe 1000 rounds together), one of the values in the vector is updated randomly. I guess I could do this by using an Java array and calling the aset method, but this would bre...

Clojure: How to get meta-data of functions ?

I am trying to get meta-data of all built-in Clojure functions. In previous question I've learned that this can be achieved using something like ^#'func_name (get the var object's meta data). But I didn't manage to do it programmatically, where func-name is not known in advance. For example trying to get the metadata of the last funct...

Does anyone know of a good reference for DSL design?

I've been looking into designing some Domain Specific Languages which I will probably implement in Clojure, but I really don't have any idea of what's involved. The languages I have in mind are intended to be abstract languages that are readable by domain experts with little or no programming background. Does anyone know of any tutoria...

Will Clojure run on Azure Now?

I saw that Microsoft announced Java support on Azure today at PDC. Does that mean it will be able to run Clojure (and other JVM languages) as well? ...

Clojure: lazy magic

Almost 2 identical programs to generate infinite lazy seqs of randoms. The first doesn't crash. The second crash with OutOfMemoryError exception. Why? ;Return infinite lazy sequence of random numbers (defn inf-rand[] (lazy-seq (cons (rand) (inf-rand)))) ;Never returns. Burns the CPU but won't crash and lives forever. (last...

How to improve Clojures error messages

I've been playing a bit with Clojure and so far is fairly impressed, but one thing that I keep running into is wierd error messages from Clojure. This comes in two forms: Java errors, like null pointer exceptions and in clojure syntax errors, like missing parenthesis pair. I was wondering if anyone know of a way to get better error messa...

passing events from erlang to Clojure

I'm looking for a way to pass events back and forth between Clojure and erlang. has someone done this before? how should I encode the (immutable) messages in a flaxable general way? Should IPC be used for this? what sort? where has this gone wrong for you in the past? ...

remove compile messages from clojure build failure backtraces

I would just love a way to filter out the back-traces from the compilation process and see only the messages from the running of my program. I'm currently using La Clojure for Intellij, though I also use slime/emacs. ...

How does one start a thread in Clojure?

I've read a lot about how great Clojure is when it comes to concurrency, but none of the tutorials I've read actually explain how to create a thread. Do you just do (.start (Thread. func)), or is there another way that I've missed? ...

Clojure equivalent of Erlang's DETS / Persistent-Maps

I'm looking for the equivalent of Erlangs DETS for a persistent key/value store, except with out DETS 2G table size limit. ...

Scoping rules in Clojure

Even though I have used Clojure, I hadn't looked at the scoping rules in detail. I am getting more confused as I read the documentations. I made a small test to try out the scoping resolutions and am apalled at the complexity. Could somebody explain the intent and various rules that Clojure uses? (def x 1) (defn dummy-fn2[] (+ x 1)...

Clojure: Unable to resolve symbol. I'm stumped.

When I paste this code into a REPL, it works fine: (use 'clojure.contrib.seq-utils) (defn- random-letter [] (char (+ (rand-int 26) 97))) (defn- random-digit [] (rand-int 10)) (defn- random-password "Returns an 8-character password consisting of letters and digits as follows: aa1aa1aa" [] (let [password (interpose '((random-digit))...

How can I configure my project.clj so that Leiningen finds my sources under a non-standard directory structure?

It seems Leiningen's compile task looks for source packages to start immediately under the /src directory. I use both Java and Clojure in my project, so my /src directory looks like this: /src/java/myapp /src/clojure/myapp Right now Leiningen is looking for /src/myapp and it's failing out during the compile. Related, I'd like to know...

Representing A Tree in Clojure

What would be a idiomatic way to represent a tree in Clojure? A / \ B C /\ \ D E F Such as the one above, performance is not important and tree's wont grow more than 1k elements. ...

Setting the Classpath and Accessing code from book: Programming Clojure

(I posted this same question on the Clojure list but haven't got an answer yet. Is anyone here ready to help?) I am going through Programming Clojure and I recently downloaded the code from the books official website. For other utils I can do, for example, (require 'clojure.contrib.str-utils) and it works. But how do I load code from th...

In Which Cases Is Better To Use Clojure?

I develop in Lisp and in Scheme, but I was reading about Clojure and then I want to know, in which cases is better to use it than using Lisp or Scheme? Thanks ...

Clojure can't find .clj in local directory, . and ./classes on CLASSPATH

When I evaluate (use 'hello) to load hello.clj, the REPL complains with the following error: java.io.FileNotFoundException: Could not locate hello__init.class or hello.clj on classpath: (NO_SOURCE_FILE:0) I'm invoking the REPL like this: java -cp "/Library/Java/Extensions/servlet-api-2.5-20081211.jar:... lots of jarfiles ...:/Librar...

Defining a SPI in Clojure

I'm looking for an idiomatic way(s) to define an interface in Clojure that can be implemented by an external "service provider". My application would locate and instantiate the service provider module at runtime and delegate certain responsibilities to it. Let's say, for example, that I'm implementing a RPC mechanism and I want to al...

Financial Account pattern implementation in Clojure: ref or agent?

I'm working my way through Fowler's Analysis Patterns and programming examples for myself in Clojure as way of developing a better understanding of both. Putting persistence/durability issues to the side for the moment[1], it seems that Clojure refs with their synchronization would be the obviously best approach. On the other hand, giv...

Clojure: How to create a function at runtime

I want to generate a fn totally at runtime (i.e. the name and the arg symbols are decided at runtime, not in code) What's the best way to achieve this ? For example how can I implement the following function ? (defn gen-fn [name arg-symbols body] ... ... which would be used like this: (gen-fn "my-func-name" (symbol "x") (symbol "y...