Reproducing a sociology simulation paper about social norms and the tendency towards low-quality exchanges and suboptimal outcomes. The Unaccountability Machine 1 by Dan Davies is broadly about how and why dysfunctional systems produce outcomes nobody seems to want. It also contains a tidy introduction to Cybernetics 2 and ideas like the viable system model 3 and requisite variety 4 . Reading that…
Using Cognitect’s aws-api library to work with AWS is nice and easy (and simple). This post shows how to use it with AWS Transcribe for speech-to-text. aws-api is an idiomatic, data-oriented Clojure library for invoking AWS APIs. Comparisons Previously I’d used Amazonica for working with general AWS services, or more focused libraries like Faraday for working with DynamoDB. Amazonica takes a…
GraalVM enables interesting new interop scenarios between its hosted languages. This post demonstrates some polyglot interop between Clojure as a host language and JavaScript as the hosted language. You’ll need to run this Clojure code on a GraalVM SDK, and we’ll want to import some org.graalvm.polyglot types: ( ns polydact.core ( :import ( org.graalvm.polyglot Context Value ) (…
Clojure.spec has been available (in alpha) for some time, and there are great talks and resources like the rationale and official guide . This post supplements those with some common questions and issues I’ve seen. These are mostly things I’ve experienced myself or seen on Stack Overflow , Clojurians Slack , r/Clojure or Twitter . The community is extremely helpful so reach out if you have…
I had an itch to implement some basic CSS selectors for Hickory , a Clojure HTML representation. Having done something similar in F# for XPath and HTML I thought the same approach would be a good starting point. My first step was to build a parser for the CSS selector syntax I was interested in. After some entertaining trial and error in the REPL I had a Minimum Viable Parser using Instaparse.…
GraalVM 1.0.0-RC7 adds HTTPS as a supported protocol, and this is a brief walkthrough for using it in a Clojure project with GraalVM Community Edition for macOS. See this example project for a demo. How To Enable HTTPS protocol support with native-image options: --enable-https or --enable-url-protocols=https Configure path to libsunec (Sun Elliptic Curve crypto) This shared object comes with the…
Parsing is fun, and I’ve covered some simple Parsec-style parsers in previous posts, but this one’s about Clojure and Instaparse. Instead of building up parsers with combinators, Instaparse takes a grammar as a string and generates a parser. I think this makes for more concise parser definitions that are both easier to write and understand after the fact. Bowling Scores I’m not much of a bowler,…
This post covers some toy problems I’ve solved with Clojure’s core.logic . Introduction Logic and constraint-based programming interest me, which might explain why I enjoy SQL so much. I like the idea of describing a problem declaratively and having a computer give an exhaustive set of answers. For some problems, a “mechanical” solution might require much more code, and maybe much more complexity.…
GraalVM makes it possible to compile JVM-based programs ahead-of-time into a native executable, with significant improvements to startup time, resource usage, etc. This post will demonstrate a CLI tool written in Clojure and compiled to a native binary, and compare its performance to the JVM-based version. Update 2018-05-25: I created a simple Leiningen plugin lein-native-image to simplify…
Clojure.spec for functions by example: their inputs, outputs, and the relationships between them. Updated 9/6/2018. Simple Input & Output We have a simple function that takes a single argument and returns a set: ( defn digits "Takes just an int and returns the set of its digit characters." [ just-an-int ] ( into # {} ( str just-an-int ))) Function specs are typically defined with s/fdef . Let’s…