clojure

Calculating the Moving Average of a List

This weekend I decided to try my hand at some Scala and Clojure. I'm proficient with object oriented programming, and so Scala was easy to pick up as a language, but wanted to try out functional programming. This is where it got hard. I just can't seem to get my head into a mode of writing functions. As a expect functional programm...

why can't I declare a namespace and a method in a do using Clojure

I try to write a macro in clojure that sets up a namespace and automatically adds a few methods to it. My macro wasn't working and I tracked it down to a do statement. It is not possible to declare a new namespace in a do and immediately afterwards declare a method in that namespace. Why? This does not work: (ns xyz) (do (ns abc) (...

Compojure Templating Pages.

I have a bunch of static html files that share same header and footer. I would like to share this header and footer across all pages. For now i use the following routed but it is a bit ugly, and i have to take care of all special cases. Is there an easyway to dothis such as the php's include function? (defroutes my-app (GET "/" ...

Building a Clojure app with a command-line interface?

I just started w/ Clojure (coming from Ruby) and I would like to build an small app with a command-line interface. How do I handle input/output to a CL? I noticed that there is a clojure.contrib.command-line, but documentation is slim. http://github.com/richhickey/clojure-contrib/blob/ffa868411cda6c617105b52b4f6f9e0f37ee8c24/src/clojur...

Why is Clojure much faster than Scala on a recursive add function?

A friend gave me this code snippet in Closure (defn sum [coll acc] (if (empty? coll) acc (recur (rest coll) (+ (first coll) acc)))) (time (sum (range 1 9999999) 0)) and asked me how does it fare against a similar Scala implementation. The Scala code I've written looks like this: def from(n: Int): Stream[Int] = Stream.cons(n, from(n+...

Getting local variables from a stack frame on the JVM

Is there any way to get a map or other data structure of the local variables in the current scope in on the JVM without using a debugger? That is, to get the locals of the current stack frame? I know that there are stacktrace objects, but StackTraceElement has no way to get access to any state. It just tells you what method was called ...

A few questions about "hello world" in clojure

I have a couple of questions about Hello World in Clojure: (println "Hello, world!") Since 'println' is used, does this mean some Java libraries are included in the default namespace by default, just as in Grails? Why are the braces needed around the statement? Judging by other examples (below), braces are commonplace: (let [i (atom...

Why is lockless concurrency such a big deal (in Clojure)?

I'm told that Clojure has lockless concurrency and that this is Important. I've used a number of languages but didn't realize they were performing locks behind the scenes. Why is this an advantage in Clojure (or in any language that has this feature)? ...

What factors could determine whether Clojure, Scala or Haskell will gain traction?

Given that it's impossible to see into the future, what factors related to Clojure, Scala or Haskell are likely to determine whether one of them catches on? Are there cultural or economic issues that could give one of these languages an advantage over the others? Or are none of these languages likely to gain traction because of their c...

which clojure library interface design is best?

I want to provide multiple implementations of a message reader/writer. What is the best approach? Here is some pseudo-code of what I'm currently thinking: just have a set of functions that all implementations must provide and leave it up to the caller to hold onto the right streams (ns x-format) (read-message [stream] ...) (write-mes...

Finding advanced programming classes

I have an intense job and large family. Finding time and energy to explore/expand technical skills on my own is difficult. I'd like to find some courses on advanced software topics without having to enroll in a PhD program. I'm not quite sure where to start. There are some great resources out there for learning different programming top...

How do I create a distributable application in Clojure?

What is the 'least work' approach to distributing a Clojure application? And is this different from the 'best' approach? For example here is a trivial 'application' that I want to be able to send to someone: (doto (javax.swing.JFrame. "Hello World") (.add (javax.swing.JLabel. "Clojure Distributable")) (.pack) (.show)) I imagin...

Clojure Remove item from Vector at a Specified Location

Is there a way to remove an item from a vector based on index as of now i am using subvec to split the vector and recreate it again. I am looking for the reverse of assoc for vectors? ...

Calling Clojure from within R?

Is there any link between R and Clojure? I am aware of Incanter, but am ideally looking for an R package for Clojure or any future plans for one, in order to call clojure from within R. ...

Groovy vs Scala [vs JRuby vs Closure vs Jython]

I'm planning to broaden my perspectives in JVM platform, and I've got a dilemma: what should I learn first? Could you please explain, what are the advantages of Groovy, Scala and other languages for JVM? Thanks. ...

Clojure Application Data Exchange

I would like to move data back and fourth between clojure applications. Application settings and some state information. I can not decide between using xml or s-expressions, what do you think pros and cons of each approach? ...

How to check if a symbol is resolvable in the current namespace?

I want to check if a symbol is resolvable in the current namespace. What's the canonical way to do this? ...

Is Clojure closer to Scheme or Common Lisp from a beginner's perspective?

If I want to learn Clojure, should I start by learning Scheme or Common Lisp? Or is Clojure different enough from both of these, that I should just start learning Clojure by itself? ...

Why Clojure over other JVM Lisps: Kawa, Armed Bear or SISC?

The JVM already had three Lisps before Clojure arrived on the scene: Kawa, Armed Bear and SISC. What gap does Clojure fill that was left by those Lisps? ...

Which functional language(s) does Clojure share the most in common with?

I don't know much about functional programming but am interested in learning Clojure. Are there any functional languages that would be a good point of reference to understand how functional programming works in Clojure? Or is Clojure different enough in its functional programming approach that I would be better off to just focus on C...