clojure

http request from Google App Engine

I'm trying to make http requests from my Google App Engine webapp, and discovered I have to use URLConnection since it's the only whitelisted class. The corresponding Clojure library is clojure.contrib.http.agent, and my code is as follows: (defroutes example (GET "/" [] (http/string (http/http-agent "http://www.example.com"))) (rou...

How can I examine the JVM bytecode for a clojure function?

In trying to optimize C and LISP, looking at the assembler code output by the compiler can be a great help. Clojure presumably compiles to a JVM bytecode that would be equally helpful. How do I see it? ...

What is the best way to translate the generation of a multidimensional cell array from Matlab to Clojure

I'm halfway through figuring out a solution to my question, but I have a feeling that it won't be very efficient. I've got a 2 dimensional cell structure of variable length arrays that is constructed in a very non-functional way in Matlab that I would like to convert to Clojure. Here is an example of what I'm trying to do: pre = cell(...

What's the best way to manage dependencies with CounterClockwise/Eclipse?

I have a dependency on clj-record in my CounterClockwise project. What's the best way to manage this? Copy the source code or compile to a JAR and add it as a referenced library? ...

Parse string into a tree structure?

I'm trying to figure out how to parse a string in this format into a tree like data structure of arbitrary depth. "{{Hello big|Hi|Hey} {world|earth}|{Goodbye|farewell} {planet|rock|globe{.|!}}}" [[["Hello big" "Hi" "Hey"] ["world" "earth"]] [["Goodbye" "farewell"] ["planet" "rock" "globe" ["." "!"]]]] ...

Clojure: Getting single value and map in structmap

I have a sequence of values that I get from somewhere else, in a known order. I also have one separate value. Both of these I want to put into a struct. I.e. (defstruct location :name :id :type :visited) Now I have a list (list "Name" "Id" "Type") that is the result of a regexp. Then I want to put a boolean in :visited; yielding a...

Custom Exceptions in Clojure?

I've been trying to create a user-defined exception in Clojure, and have been having all sorts of problems. I tried the method outlined here: http://en.wikibooks.org/wiki/Clojure_Programming/Concepts#User-Defined_Exceptions (gen-and-load-class 'user.MyException :extends Exception) But that doesn't seem to work in Clojure 1.2 (or I'm...

How can I get a clojure webapp to automatically redeploy?

I am developing a webapplication in Clojure and Vaadin, but I cannot get the application to autoredploy so that I just press refresh on the browser. Any ideas? ...

Expand a vector into the arguments of a function

Is there a way to expand a vector of values into the arguments of a function? e.g. something like this: (defn addnums [a b] (apply + (flatten [a b]))) (def args [[1 2 3] [1 2 3]]) (addnums *args) ...

Calling a Function From a String With the Function’s Name in Clojure

How could I call a function with a string? e.g. something like this: (call "zero?" 1) ;=> false ...

On performance of Clojure's `first` function.

I saw the following example in Rich's video on sequences http://blip.tv/file/734409 about 33-36 minutes into it: (first "abcd") => \a Now, he say that this expands to (sort of): (first "abcd") => (first (seq "abcd")) => (first '(\a \b \c \d)) So, it looks like an O(N) operation because the full copy of the string is being made. Fir...

Symbolic mathematical calculations in Clojure vs. F#.

Hello, I have come across the following F# sample and found it intriguing. http://www.codeproject.com/KB/net-languages/SymbolicCalcInFS.aspx Does Clojure have language/library facilities for doing something like this with ease? It is ok to force Polish notation for formulas, if that makes things easier. Thanks, and let me know if ther...

Recommended macros to add functionality to Clojure's defrecord constructor?

defrecord in clojure allows for defining simple data containers with custom fields. e.g. user=> (defrecord Book [author title ISBN]) user.Book The minimal constructor that results takes only positional arguments with no additional functionality such as defaulting of fields, field validation etc. user=> (Book. "J.R.R Tolkien" "The L...

can I ship a 'lein uberjar' containing some gpl3 classes?

I have a project that I have released under the GPLv3 that requires clojure.jar and clojure-tontrib.jar to run. I would really like to ship one big jar file with all of them. (perhaps with a license.txt also) Does anyone know of a clear legal explanation* if this is in keeping with the licenses? can i specify this in my license.txt...

How do you use sessions with Compojure/Ring?

I'm developing a web application using Compojure and I would hugely appreciate a small and complete example of storing and retrieving session data. Many thanks in advance, James. ...

Why does let require a vector?

I never really thought about this until I was explaining some clojure code to a coworker who wasn't familiar with clojure. I was explaining let to him when he asked why you use a vector to declare the bindings rather than a list. I didn't really have an answer for him. But the language does restrict you from using lists: => (let (x 1...

How do you evaluate a java.lang.String in clojure

How would I eval to the following? (defn run-clojure-func [] (println "welcome")) (defn -main [& args] (eval (*func* (first args))) java exam.Hello "run-clojure-func" ...

Compojure binds HTTP request params from URL, but not from a POST form

Compojure does not bind the fields in a POST form. This is my route def: (defroutes main-routes (POST "/query" {params :params} (debug (str "|" params "|")) "OK...") ) When I post a form with fields in it, I get |{}|, i.e. there are no parameters. Incidentally, when I go http://localhost/query?param1=value1, params is not em...

Python's StringIO for Clojure

Hi, Is there something equivalent to Python's StingIO for Clojure? I'm trying to write a report generating/literate programming system similar to Sweave and Pweave for Clojure. I'm currently using a temp file, but I'd prefer using something similar to StringIO. ...

How do I create a primitive two-dimensional (2d) array of doubles in Clojure?

A Java API I am Clojure interoping with requires that I pass it a 2d array of doubles; double[][]. How do I create a primitive 2d array of doubles in Clojure? I am looking for something like this (double-array-2d [[1 2] [3 4]]) This function would have a Java return type of double[][]. ...