On Performance and Java Interoperability: Clojure vs. Scala

I think either language will be fast enough for you. When comparing Python and Java, it seems a bit unreasonable to blame the language for the speed difference. Java is compiled JIT (except on mobile devices*) whereas Python is interpreted. Just because both use a bytecode does not mean the implementations will have even remotely … Read more

Clojure – named arguments

In Clojure 1.2, you can destructure the rest argument just like you would destructure a map. This means you can do named non-positional keyword arguments. Here is an example: user> (defn blah [& {:keys [key1 key2 key3]}] (str key1 key2 key3)) #’user/blah user> (blah :key1 “Hai” :key2 ” there” :key3 10) “Hai there10” user> (blah … Read more

Why does Clojure have 5 ways to define a class instead of just one?

This is a mix of three different factors: The particular type system of the jvm The need for slightly different semantics for different use cases when defining types The fact that some of these were developed earlier, and some later, as the language has evolved. So first, let’s consider what these do. deftype and gen-class … Read more

Generating permutations lazily

Yes, there is a “next permutation” algorithm, and it’s quite simple too. The C++ standard template library (STL) even has a function called next_permutation. The algorithm actually finds the next permutation — the lexicographically next one. The idea is this: suppose you are given a sequence, say “32541”. What is the next permutation? If you … Read more

What is the :: used for in clojure?

The double colon is there to fully qualify keywords with your current namespace. This is intended to avoid name clashes for keywords which are meaningful for different libraries. Without fully qualified keywords you might accidentally overwrite some values in a map and break compatibility with a library.

Interpreting a benchmark in C, Clojure, Python, Ruby, Scala and others [closed]

Rough answers: Scala’s static typing is helping it quite a bit here – this means that it uses the JVM pretty efficiently without too much extra effort. I’m not exactly sure on the Ruby/Python difference, but I suspect that (2…n).all? in the function is-prime? is likely to be quite well optimised in Ruby (EDIT: sounds … Read more