#Programming Blog

core.async and Blocking IO

clojure core.async go

Some time ago I wrote about Asynchronous workflows in Clojure. With the recent release and excitement of core.async, I thought it a good time to revisit that post.

While there are already some good examples and comparison-with-go posts out there, I’d like to focus on an area often misunderstood, namely async frameworks and blocking APIs (most commonly blocking IO). It’s important to understand the implications of blocking IO and its effects on ‘async code’, in this case core.async.

Read more...

Datomic Bootstrap

clojure datomic

A simple SQL scenario;

Read more...

Announcing Frins, a practical unit of measure calculator DSL for Scala

scala frinj frins

I am proud to announce a new Scala project called “Frins.”

Frins is a practical unit-of-measure calculator DSL for Scala.

Key features:

  • Tracks units of measure through all calculations, allowing you to mix units of measure transparently
  • Comes with a huge database of units and conversion factors
  • Inspired by the Frink project

Full source code is available on GitHub.

To whet your appetite, head straight over to the example calculations.

How Frins Came About

About a year ago, I created Frinj. With Frinj, I tried to marry some of the joys of one of my favorite programming languages (Frink) with the Clojure REPL. I was quite pleased with the results, and the response was encouraging.

Read more...

EDN Parser in Scala

scala

Taken from edn-scala

Read more...

Scheme in Scala

scala lisp

In this post, I present some of my experiences writing a Scheme interpreter in Scala (as an external DSL) and compare it with my recent similar experiences in Clojure and F#.

Overall, the Scala solution is very similar to the F# one. Not very surprising, since the problem lends itself well to case classes / discriminated union types and pattern matching. One difference is more type declarations in Scala, due to the lack of Hindley-Milner type inference. Scala uses a “flow-based” type inferrer, which is less powerful than ML but apparently works better for OO subclasses, etc. I will look into this in a future blog post.

Read more...

Comparing FP REPL Sessions

scala clojure fsharp

Functional programming is great; higher-order functions, closures, immutable data-structures, lazy sequences etc.

Most languages comes with a REPL (or ‘interactive’ prompt), where you can play with these features at your leisure. Dynamically typed languages are a bit more convenient in the REPL, but not by as much as you might think. Also, F# type providers closes the gap even further.

Here’s a typical, hit-a-JSON-endpoint-and-look-at-the-data session in Clojure;

$ lein repl

user=> (def res (slurp "http://www.bbc.co.uk/tv/programmes/genres/drama/scifiandfantasy/schedules/upcoming.json"))

user=> (require 'clojure.data.json 'clojure.walk)
user=> (def json (->> res clojure.data.json/read-str
                      clojure.walk/keywordize-keys))

user=> (->> json :broadcasts (filter #(>= (:duration %) 6300))
            (map :programme) (map (juxt :title :pid)))
(["Lady in the Water" "b00l5wdn"] ["Lady in the Water" "b00l5wdn"] ["Lady in the Water" "b00l5wdn"] ["Lady in the Water" "b00l5wdn"])

Nice, clean and very powerful, virtually zero ceremony. Doing the same in Scala, is just a little bit more awkward;

Read more...

Scala and me

fsharp scala clojure sicp

This epic journey (yeah right) began at university with discovering the mighty SICP, still the best book on programming I’ve read (and let’s face it, the best I will ever read). After that profound experience, I kept an eye on the Lisp/FP world and wrote some toys in Scheme, ELisp, and OCaml every now and then. One thing that dawned on me was that none of these languages had much practical use; they weren’t very applicable to real-world software problems. While very clever and mind-expanding, they seemed mainly an academic exercise. There were zero jobs out there using these languages. Heck, hardly any of my peers had heard of or cared about them.

Read more...

Clojure Hacking on the Samsung ARM Chromebook

clojure chrome arm rpi

I recently switched to the Samsung ARM Chromebook for all my laptop needs. The pitch is quite appealing: £200, dual-core ARM Cortex-A15s, good keyboard, totally fanless (CPU is passively cooled), good battery life, and 1kg weight. The one downside is its quite limited RAM size, just 2GB. But with a decent swap file, I’m running multiple JVMs (with Datomic, Elasticsearch, CLJS compiler, etc.) without any hiccups.

Out of the box, it runs ChromeOS, which I have to say is pretty stellar for browsing and consuming content on the web. It is also possible to run any Linux distribution you wish on this machine; Google has an outspoken strategy to enable it.

Read more...

Flexible multi consumer/producer pipelines

clojure

TL;DR: Pipejine - a lightweight Clojure library for multi-threaded producer/consumer pipelines supporting arbitrary DAG topologies.

Recently, a colleague and I faced a problem where we needed to optimize the total running time of a complicated calculation. This calculation involved several asynchronous steps getting data from other systems (like Elasticsearch and other home-grown services), along with some number crunching and tallying up the results at the end. Here is a simplified example of the system:

Read more...

Embedding a new runtime into your legacy C/C++ app

.net csharp fsharp gnu guile javascript lisp lua mono

Let’s say you have a big legacy C++ app. Then you’re undoubtedly covered by Greenspun’s tenth rule. Let’s also say that your home-grown, buggy, and slow DSL/scripting language has been pushed to its limit and cannot be tweaked any further. What do you do? How can you replace it?

As you might expect, this is quite a common problem, and embedding scripting languages into a big C/C++ monolith is popular. There are famous examples from gaming where Lisps and Lua are widely used.

Read more...