clojure

How do I write a Clojure macro to create a regular expression from a String?

I'm creating a convenience macro. Part of the convenience is that a regular expression can be specified with just a String, rather than the #"re" notation. The one part I can't figure out is how to get the macro to take the String and rewrite it as a Clojure regex (e.g., produce the #"re" notation). I think it's a syntax / escaping prob...

How to start IntelliJ idea despite of a plug-in error

Hi, I have a problem with my IntelliJ idea 9 IDE. I installed the La Clojure plugin (http://plugins.intellij.net/plugin/?id=4050) and the IDE needed to restart. Now I get the following error on startup and it won't let me continue working: java.lang.AssertionError: Source file C:\Users\foo\.IntelliJIdea90\system\plugins\org.intellij.cl...

How to get a list of files matching a filemask (wildcard) in Clojure?

Is there an easy way to get a list of files matching a specified filemask? By filemask I mean classic wildcard, not regexp. I can use file-seq and then filter with regexp created from a wildcard. However, it is not trivial (consider escaping etc.) I am also aware of FilenameUtils.wildcardMatch() from Apache Commons, but I'm reluctant t...

Writing a Parser (for a markup language): Theory & Practice

I'd like to write an idiomatic parser for a markup language like Markdown. My version will be slightly different, but I perceive at least a minor need for something like this in Clojure, and I'd like to get on it. I don't want to use a mess of RegExes (though I realize some will probably be needed), and I'd like to make something both...

List available updates for dependencies listed in project.clj

I'm using lein to manage my project, and I have a number of :dependencies as well as :dev-dependencies. Is there a way to find out if there are updates available for these dependencies? ...

How does functional programming apply to simulations?

How do functional programmers and functional languages approach the domain of simulations, which seem to be most naturally handled by object-oriented languages? Are there open-source examples of complex simulations written in a (mostly) functional style? What changes of perspective would an OO-programmer need, in order to approach simu...

Are clojure function cyclic dependencies specifically disallowed by design, or is it just a reader behaviour?

If I do the following in clojure (defn sub1a [a] (cond (= a 0) 0 true (sub1b (- a 1) ))) (defn sub1b [a] (cond (= a 0) 0 true (sub1a (- a 1) ))) (println (sub1a 10)) I get the following error: java.lang.Exception: Unable to resolve symbol: sub1b in this context But if I do the following: (defn sub1a [a] (co...

Is it possible to redefine Java methods from Clojure?

Using multimethods we are able to add methods to existing Java classes. My question is whether it is possible to redefine one specific method, and how, from Clojure code. For instance, if you have the following class, public class Shape { public void draw() { ... } } I'd like to be able to run something to add a before...

How to map clojure code to and from JSON?

I have a crazy idea, which involves putting some clojure code into CouchDB and writing views that query it. I don't want to store the clojure code as plain text, because then I would have to worry about parsing it in the views. Formatting and comments don't need to be preserved, but the code should be able to go in and out of the databas...

Clojure/Java: Java libraries for spectrum analysis of sound?

Hi folks, I am looking for a library that can accept a chunk of audio data and return the average amplitude over time within a given frequency band. I've already asked this question over at comp.dsp, but it's clear to me that acquiring the know-how to build this on my own using a basic FFT library is going to require more time and energ...

How does Hadoop's RunJar method distribute class/jar files across nodes?

I'm trying to use JIT compilation in clojure to generate mapper and reducer classes on the fly. However, these classes aren't being recognized by the JobClient (it's the usual ClassNotFoundException.) If I AOT compile the Mapper,Reducer and Tool, and run the job using RunJar, everything seems fine. After looking through the source, it s...

Clojure on the CLR

I'm interested in investigating Clojure on the CLR. I see that there is a port--but I'm always a bit leery of these second-class citizens (i.e. they don't have the stability or functionality of the original). I'd less inclined to spend much time at this point if generally people find Clojure on the CLR immature--I simply don't have the t...

How to convert a sequence to a byte[] in Clojure?

I need to write raw bytes to the file. I do it with: (.write (FileOutputStream "/path") bytes) ...where bytes must be of type byte[]. Please note it cannot be Byte[]. I tried to convert my sequence with both (bytes) and/or (into-array) functions and got frustrated, one example: user=> (bytes (into-array (filter #(not (= % 13)) (to-b...

Beginner question about heap and garbage in Clojure

I have a question about Clojure: I am trying to learn the language by going through Project Euler and I don't understand what is going on under the hood: The following code is designed to use return a list of all prime numbers up to lim. I would think that it should be O(n) in heap-space because I make a list of all the numbers up to li...

Idiomatic way to pass a method name for evaluation in Clojure?

I'm passing the name of a function for use in another method. (defn mapper [m function] (cond (= '() m) '() true (cons (function (first m)) (mapper (rest m) function)))) (println (map_ '((blue red)(green red)(white red)) #'first)) Is there a more idiomatic way to do this in clojure? ...

Mapping Pixels to Data

I've written some basic graphing software in Clojure/Java using drawLine() on the graphics context of a modified JPanel. The plotting itself is working nicely, but I've come to an impasse while trying to converting a clicked pixel to the nearest data point. I have a simple bijection between the list of all pixels that mark end points ...

Clojure Parallel Mapping and Infinite Sequences

Let's say I define the sequence of all natural numbers in the following way: (def naturals (iterate inc 0)) I also define a function mapping the naturals to nil that takes a while to compute like so: (defn hard-comp [_] (Thread/sleep 500)) Note the computation time to evaulate the following s-expressions as measured by clojure.core...

Detecting Unicode text ligatures in Clojure/Java

Ligatures are the Unicode characters which are represented by more than one code points. For example, in Devanagari त्र is a ligature which consists of code points त + ् + र. When seen in simple text file editors like Notepad, त्र is shown as त् + र and is stored as three Unicode characters. However when the same file is opened in Fire...

Scheme and Clojure don't have the atom type predicate - is this by design?

Common LISP and Emacs LISP have the atom type predicate. Scheme and Clojure don't have it. http://hyperpolyglot.wikidot.com/lisp Is there a design reason for this - or is it just not an essential function to include in the API? ...

Can you implement any pure LISP function using the ten primitives? (ie no type predicates)

This site makes the following claim: http://hyperpolyglot.wikidot.com/lisp#ten-primitives McCarthy introduced the ten primitives of lisp in 1960. All other pure lisp functions (i.e. all functions which don't do I/O or interact with the environment) can be implemented with these primitives. Thus, when implementing or porting lisp, the...