===================
== Martin Trojer ==
Programming Blog

===================

Retrofitting the Reloaded pattern into Clojure projects

clojure

Stuart Sierra has done a great job with clojure.tools.namespace and the reloaded Leiningen template. If you haven’t heard about this before, please have a look at c.t.n’s readme and watch this presentation.

I have retrofitted this pattern into two rather large Clojure projects (20,000 and 5,000 lines) with several modules, and here are some of my findings.

Removing global state

The first step is to find all resources that need to be “lifecycled.” Typical examples are Jetty servers, database/message bus clients, etc. It’s common that these resources are in a (defonce server (atom ...)) form. I tend to grep for defonce and atom to find these items.

Read more...

Non tail-recursive functions in core.async go blocks

clojure core.async go

I’ve been using various Go examples and tutorials to take a deeper look into core.async. The CSP pattern is very interesting and powerful; it’s a good move for Clojure to “throw in” with Go and push this style of programming.

core.async works at the s-expression level, where some other JVM solutions (Kilim, Pulsar) do the same at the byte-code level. The main benefit of doing these transforms at the s-expression level is that they are applicable to ClojureScript, where CSP can be a very neat way out of callback hell. David has written about this.

Read more...

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...
Previous Page 3 of 7 Next Page