clojure

Is this a sensible monad for mutable state in Clojure?

I've been experimenting with monads in Clojure and came up with the following code, where a monadic value/state pair is represented by a mutable Clojure deftype object. Since the object is mutable, an advantage would seem to be that you can write monadic code without needing to construct new result objects all the time. However, I'm pr...

What is the Clojure equivalent of __FILE__ (found in Ruby & Perl)

In ruby I frequently use File.expand_path(File.dirname(__FILE__)) for loading config files or files with test data. Right now I'm trying to load some html files for a test in my clojure app and I can't figure out how to do it without hard coding the full path to the file. edit: I'm using leinigen if that helps in any way ref: __FILE__...

Serving binary files from the database with compojure

I have the following routes definition: (require '[compojure.core :as ccore] '[ring.util.response :as response]) (def *main-routes* (ccore/defroutes avalanche-routes (ccore/GET "/" [] "Hello World 2") (ccore/GET "/images/:id" [id] (get-image-response id)))) In this example, requesting / works like a charm ...

Ambiguity in Clojure attribute map

In the documentation for Clojure special forms (http://clojure.org/special_forms) the example for :pre and :post looks like this: (defn constrained-sqr [x] {:pre [(pos? x)] :post [(> % 16), (< % 225)]} (* x x)) How can Clojure tell if the map containing the meta-data is not the definition of the function? Shouldn't the m...

Clojure compile-time escape mechanism

The language Forth offers a "compile-time" escape mechanism where code can be executed immediately, while the compiler is running (not at run-time). You can include print statements, for example, to debug tricky syntax or type errors). Does Clojure have anything similar? I am getting a compile-time IllegalArgumentException in one of my ...

Setting Clojure "constants" at runtime

I have a Clojure program that I build as a JAR file using Maven. Embedded in the JAR Manifest is a build-version number, including the build timestamp. I can easily read this at runtime from the JAR Manifest using the following code: (defn set-version "Set the version variable to the build number." [] (def version (-> (str "j...

Implementing Java generic interface in Clojure

I'm trying to get the hang of clojure in a selenium2/webdriver project using the webdriver-clj wrapper for webdriver. However, since the webinterface is heavily scripted, I need to have an option to wait until certain elements are created by the script, instead of on page load. So I was trying to create a wait-for function in clojure, ...

Is there a nice and easy installer for Clojure on Mac OS (Leopard)?

I found the following guide: http://mark.reid.name/sap/setting-up-clojure.html but it seems like a whole lot of manual steps, and I bet it is out of date already. Installing ClojureBox on Windows was a breeze. Does anyone know of a simple installer for it? Where can I download it, and what are the steps? Thanks! EDIT: Tried installin...

Previous expression in clojure repl

In the python repl, getting the result of the previously input expression is easy: >>> 1+2 3 >>> _ 3 >>> Is there a way to do this in the clojure repl? ...

How do I design and implement a programming language?

This question is related to This question on Aardvark This question on here The past couple of years I've been thinking about things I like and don't like about languages I use. I always wanted to write my own language, but never did so. I also own both the Lego RCX and NXT, but most of the time I never actually make my robots do an...

When to use `constantly` in clojure, how and when are its arguments evaluated?

In the accepted answer to another question, http://stackoverflow.com/questions/3997910/setting-clojure-constants-at-runtime the clojure function constantly is used. The definition of constantly looks like so: (defn constantly "Returns a function that takes any number of arguments and returns x." {:added "1.0"} [x] (fn [& args] x)...

Clojure: finding out if a collection is seq-able

So there's list?, seq?, vector?, map? and so on to determine what type of collection the argument is. What's a good way of telling the difference between a map (i.e. something that has key-value pairs) a collection (i.e. things that contains values) a non collection value like a string. Is there a better way than #(or (seq? %)...

How can I format a map over several lines with pprint?

pprint's docs are kind of a brick wall. If you pprint a map, it comes out on one line like so: {:a "b", :b "c", :d "e"}. Instead, I'd like to be pprinted like this, optionally with commas: {:a "b" :b "c" :d "e"} How would one do that with pprint? ...

Will reading the Little Lisper help me in learning clojure ?

I plan to pick up the clojure language. I have at my disposal an old book: The Little Lisper I know there are more recent versions of it (The Little Schemer) but I'm wondering if it will help ease me into picking up Clojure. Or should I find other learning resource ? ...

Partition a number sequence in clojure

I have the following input: (def nums [123456789012 123456789012]) I'd like the following output: [[1234 5678 9012] [1234 5678 9012]] *note both of these sequence contain numbers not strings... I figured this would be really simple by doing the following: Convert each entry into a String Partition each string by 4 Convert each...

add unique id to requests forwarded from nginx reverse proxy

Hi, We are running nginx as a reverse proxy that forwards requests to a Clojure application running Compojure, a library that wraps around Jetty and provides our application with the ability to service web requests. We currently capture logs generated by both nginx and the Clojure application (via log4j to syslog). We are unable, howev...

Testing in leiningen

I am writing a small Clojure project using leiningen with the following directory structure: project + src + org/example/project/core.clj + test + org/example/project/core.clj When I run lein test, it reports that it ran 0 tests with 0 failures, but I purposely put a test designed to fail in the test/.../core.clj file. I added th...

CLOS for Clojure?

Does there exist anything like CLOS (Common Lisp Object System) for Clojure? If there isn't, how hard would it be to write one? Thanks in advance. -- Eric Grindt ...

Idomatic way to iterate through all pairs of a collection in Clojure

Given a collection I want to iterate through all paris in a collection. Example (all-pairs seq) (all-pairs '(a b c d)) => ([a b] [a c] [a d] [b c] [b d] [c d])) Here is my idea (defn all-pairs [coll] (for [ [idx elmt] (indexed coll) other-elmt (subvec coll (inc idx))] (vector elmt other-elm))) But it doesn't feel i...

What are the breaking changes in clojure 1.3?

I have been having trouble keeping up with the list of changes in 1.3 and most importantly the changes that require me to change my code. What has changed, what is about to change, where can I get up to date lists of these? ...