Wednesday, 14 March 2012

Adding Live Unit Feeds to Frinj

A couple of weeks has passed since I've pushed Frinj to github and blogged/tweeted about it. The response have been pretty awesome, one highlight being when @stuarthalloway showed me a frinj+datomic example gist on the #datomic IRC channel. In short, the Clojure community is #badass.

Frinj comes with a big database of units and conversion factors, and while as many conversion factors are "eternal", others aren't. Exchange rates for instance has to be kept up to date to be relevant. The Frinj unit database was designed to be updatable, both for usability when doing various calculations, but also for rates that constantly change. This is the reason the frinj.calc namespace exposes the (frinj-init!) function to reset the unit database to a know baseline (in case you write over some factors etc). Clojure's support for atomically updating state is ideal for this purpose, the calculator's state is kept in a number of refs and thanks to the STM always kept consistent.

Frinj now supports live currency exchange rates, precious & industrial metals and agrarian commodities, by adding the concept of unit feeds. This is handled by the new frinj.feeds namespace, and the basic idea is to have multiple feeds sharing one ScheduledThreadPoolExecutor for periodically updating Frinj's state. The generic feed utility functions (start-feed, stop-feed, update-units!) are separated from the feed specific ones. For more information see the wiki and source. As you can imagine, these live units rates are just a couple of many potential feeds.

Currencies use the 3 letter (ISO 4217) currency acronym (uppercase), and the metals and commodities use capitalised names, see below for examples.

I've also added an new convenience namespace called frinj.repl that will initialise the built-in units, start the feeds and immigrate the rest of the frinj vars.

Next time, I'll explain how to use Frinj in ClojureScript.

Saturday, 3 March 2012

Announcing Frinj, a practical unit-of-measure calculator DSL for Clojure

I am proud to announce a new Clojure project called "Frinj".

 Frinj is a practical unit-of-measure calculator DSL for Clojure.

 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
  • Tries to combine Frink's fluent calculation style with idiomatic Clojure

Full source code available on github.

To wet your apatite head straight over to the sample calculations page to see what Frinj can do!

I also want to explain that despite it's name, Frinj was never intended to be a clone of Fink, and thus does not support the entire Frink language. But since it's a Clojure DSL, it doesn't have to!

There was a couple of reasons I decided to create frinj;
  • I wanted the power of frink but with Clojure idioms. 
  • I love Frink, and wanted to learn more about it.
  • Frink isn't open source. 
  • I wanted to have some fun.

So please take it for a spin, it's damn fun!