Ulrik Sandberg

Three Undocumented Features of JSON

Update: This article was written as an April Fool's joke, taking a stab at the fact that JSON is a closed, dumb, and pretty anemic data format. There are other interesting data formats available, such as extensible data notation (edn). JSON (JavaScript Object Notation) is widely known as JavaScript's data format, often used as a language-independent data interchange format. However, what I...

A Decimal to Roman Numeral converter in just a few lines

I recently rolled my own Decimal to Roman Numeral converter in Clojure. I was inspired by some tweets about a roman numeral code kata. The Decimal to Roman Numeral converter takes a decimal number (like 2012) and returns a string of roman numerals (like "MMXII"). The code that I came up with is around ten lines that look like this: [clojure linenumbers="table"] (def mapping (sorted-map-by >...

Finding Out Who Changed What with Datomic

Imagine that you one day were asked to implement the following requirement: "As an Administrator, I want to know what has changed in the database since a given timestamp, and also who made the changes, so that I can feel secure that nobody will screw up the database." In most projects, this would give you a major headache. There is no notion of time in a database. There might be a...

The Fantastic SUBST Function (part 4)

This post is the final part of a series of articles about LISP, a function called SUBST, Clojure, and other interesting stuff. You probably want to read the previous posts before continuing with this. Part 1: Introducing LISP Part 2: Walking through SUBST Part 3: Clojure version of SUBST In part 1 of this series, we learned about the nine special forms of LISP, the building blocks that make up...

The Fantastic SUBST Function (part 3)

This post is part of a series of articles about LISP, a function called SUBST, Clojure, and other interesting stuff. You may want to read the previous posts before continuing with this post. Part 1: Introducing LISP Part 2: Walking through SUBST In part 1 of this series, we learned about the nine special forms of LISP, the building blocks that make up the language. In part 2, we went through...

The Fantastic SUBST Function (part 2)

This post is part of a series of articles about LISP, a function called SUBST, Clojure, and other interesting stuff. You may want to read the previous post before continuing with this post. Part 1: Introducing LISP In part 1 of this series, we learned about the nine special forms of LISP, the building blocks that make up the language. In this part we will go through how the SUBST function works...

The Fantastic SUBST Function (part 1)

When John McCarthy in 1960 wrote his famous paper on the programming language LISP, he used a particular function to illustrate what you could do with the language. The language consisted of only nine "special forms", primitive building blocks by which any computable function could be created. The function was called SUBST, and it included all nine of the special forms. It was a remarkable...

Getting ShowOff source code high-lighting for Clojure

ShowOff is a presentation software where you create your slides by writing simple text files containing markdown formatting. Styling is done using CSS. The slides are served by a web server and can be displayed in a web browser. With a simple command, a presentation can be deployed on Heroku for everyone to see. ShowOff can even execute code and show the result (currently that's possible for Ruby...

Clojure third language officially supported on Heroku

According to this blog entry on Heroku, Clojure becomes the third language officially supported on the Cedar stack, after Ruby and Node.js. They write: - "Clojure combines the expressiveness of Lisp, the agility of a dynamic language, the performance of a compiled language, and the wide applicability of the JVM in a robust, production-ready package. Clojure is a practical language designed to...

Deploying a Clojure web app on Heroku

Heroku is a cloud application platform for Ruby/Rails and Node.js. However, the Cedar stack on Heroku makes it possible to deploy other types of applications. In this blog entry, I will first describe how to write a simple Clojure web app using the Ring library and the build tool Leiningen. Then I will show how to deploy this Clojure web app on Heroku, using nothing but Git. I will make a change...

Numerical Integration (With Precision)

In a previous blog entry, I explained the higher-order function sum and how to use the Substitution Model to follow the execution of a function. In this entry, I will use the sum function to perform numerical integration, and in the process run into some pitfalls of Java's BigDecimal. I will show how the language Clojure provides an elegant solution to the "exact quotient cannot be represented"...

The Substitution Model: A Tool For Understanding Recursion

Section 1.3 in Structure and Interpretation of Computer Programs is about Formulating Abstractions with Higher-Order Procedures. As an example, the authors use three simple sums: a sum of an integer range a sum of the cubes of an integer range a sum of a series that converges to π/8 The purpose is to highlight what is common between them and what differs. The differences boil down...