background preloader

Clojure

Facebook Twitter

CLHS: Section 24.1.2.1. Feature Expressions - Clojure Design. Problem Writing programs that target Clojure and ClojureScript involves a lot of copy and pasting. The usual approach is to copy the whole code of one implementation to a source file of the other implementation and to modify the platform dependent forms until they work on the other platform. Depending on the kind of program the platform specific code is often a fraction of the code that works on both platforms. A change to platform independent code requires a modification of two source files that have to be kept in sync. To solve this problem branching by target platform on a form level would help a lot. See also ticket CLJS-27. Current Solutions cljx cljx is an implementation of feature expressions that: rewrites .cljx files containing feature expression-annotated code into .clj and .cljs files for consumption by other tools/compilers/etcoptionally applies the same transformation interactively via installation of a REPL extension lein-cljsbuild "crossovers" Potential Solution References.

Clojure and me » Search Results » Counting occurences. Counting occurences One asked me how to count occurrences of each value in a collection. I answered (reduce #(assoc %1 %2 (inc (%1 %2 0))) {} coll). Since it can take some time to get accustomed to the functional way of thought, here is how one can work such an expression out: How to count all occurrences of 42? (count (filter #{42} coll)) How to express count using reduce? (defn my-count [coll] (reduce (fn [n _] (inc n)) 0 coll)) How to count all occurrences of 42 using reduce? (reduce (fn [n _] (inc n)) 0 (filter #{42} coll)) Can you get rid of the filter? (reduce (fn [n x] (if (= 42 x) (inc n) n)) 0 coll) I’d like the result to be {42 occurences-count}. (reduce (fn [m x] (if (= 42 x) (assoc m 42 (inc (m 42))) m)) {42 0} coll) 42 is hardcoded in four places, it’s bad! (reduce (fn [m x] (if (= 42 x) (assoc m x (inc (m x))) m)) {42 0} coll) Can’t you replace {42 0} with {}?

No (inc (m x)) would fail because (m x) would return nil. How does one provide a default value when the key is not found ? Easy! Counting occurences. My Clojure explained solutions to the s99 problems 1 to 3 | Jawher's Blog. A year (or maybe more) ago, I started toying with emacs and soon had to tweak its configuration file, which is actually a program written in elisp, a variant of the lisps family. I had no former experience with anything like lisp before, and anytime I touched the .emacs file, a pile of weird error messages would show up when starting emacs.

So I thought it might be a good idea to learn the lisp’s syntax so I’d at least know what was that unbalanced quote I kept seeing in .emacs snippets in the internets. With time, I started appreciating more and more lisp’s minimalistic syntax, and here I am now, spending more and more time toying with Clojure, a modern Lisp variant that runs on the JVM (my platform of choice, being a Java developer for a couple of years already).

Before that, I learned me some Scala, and to help myself get rid of my imperative programmer reflexes (for loops, variables, etc.), I started coding the solutions for the excellent s99 problems using Scala. Like this: 4clojure - clojure find last element without using last function. 2011 02 : Deep Blue Lambda. Last time, I described how to integrate Clojure into the standard Android build process. In this post, I will build on this by integrating ProGuard into the build process in an effort to make applications smaller and faster. First, I will give a brief overview of ProGuard and describe how to enable the ProGuard capability of the Android build process. Next, I will show how to configure ProGuard so that it can work with your Clojure code.

Finally, I will summarise my recommendations and let you know what to expect next in this series. The sample application I will use is available on my Clojure-Android-Examples repository on GitHub under the slimmed directory. About ProGuard As described on its web site, ‘ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier.’ Minimisation ProGuard can rid your application of unused classes, methods, and fields, leading to smaller application sizes and load times.

Optimisation Obfuscation Preverification Enabling ProGuard Next time. Creating Android applications with Clojure, Part 1 : Deep Blue Lambda. Over the past few weeks, I have started doing some application development on the Android platform. Overall, it has been a pleasant experience. The documentation, while not the best, is fairly good. Being an experienced Java programmer, I was comfortable enough to start writing real code quickly. Despite all of this, writing in Java just is not as much fun any more.

There is too much boilerplate code, and the language is missing some key features, such as closures. In this two-part series of posts, I will discuss my experiences with coding in Clojure for Android in an effort to document what has worked for me. Loading, please wait… By far, the biggest problem with a Clojure application on Android is the load time. Investigating the problem Profiling an application during this long wait time reveals that it is due to to the loading of the class clojure.lang.RT. Unfortunately, for a constrained environment such as a mobile phone, this simply takes too long.

Slimming down Clojure Footnotes. Datomic - Home. How do I connect to a MySQL database from Clojure. Clojure Tutorials.