FizzBuzz / Clojure / LightTable / Instarepl

FizzBuzz in Clojure, in an Instarepl tab in LightTable.

Screen Shot 2014-05-15 at 15.13.47

Instarepl evaluates as you type, and displays not only expression results but also the values of intermediate bindings as it goes. It is an incredibly fun and useful tool for experimenting with small bits of code: great if you’re learning the language (or learning programming generally), and great for investigating unfamiliar libraries.

They Hand Down Detention

One remarkable thing about this (a school letter questioning Nigel Farage’s being made a prefect at Dulwich College, on the grounds that he was a self-proclaimed fascist) is the way that it acknowledges, in passing, the significant effects on self-confidence and future opportunity that such an appointment will confer. I never liked prefects; having been made a prefect did something to them, put the icing on the cake of privilege. They seemed to believe, as I could not, that they were fit to wield authority, that this authority came from something about their character that was good and worthy of emulation. Whatever it was, it wasn’t intelligence or imagination*. No doubt Farage still believes he is a person of outstanding character, a born leader, and that those who believe otherwise are lesser persons, driven by base resentment. What he actually is, is Arnold Rimmer with money – a total smeghead.

* I risk insulting some old school friends here. It should be hastily added that there were always exceptions.

Cosmos and Narrative

This line of argument is only convincing if you refuse to distinguish between narrative – testimony, world-making, writing oneself into the social script – and scientific theory-making; if you see the latter as a specialized case of the former, rather than an incommensurable language game with quite different rules.

Now it may be that the Science Guy is already blurring this distinction, by narrating scientific knowledge to an audience that is an audience for narrative rather than an audience for knowledge. Such narrations are always vulnerable to cultural critique; but what that critique is critiquing is not science, but the well-meaning traduction of science – the sort of thing that scientists smile at, tolerate, and know better than. “Well, kinda”, they will say, ” but not really. It’s, uh, a bit more complicated than that. How long have you got?”.

Cosmos – which I loved as a child – is the paradigmatic attempt to render theory-making as world-making, to make the scientific image seem plausibly inhabitable for narrative-loving creatures like ourselves. So far as I know, the science in it is good: it’s an honest traduction. But its story is ultimately the story of something that is not a story, that is not lovable in the way that a story can be loved, that does not include us in the way that a story can include us – as both subjects and potential narrators – but in another kind of way altogether. Science will always keep its secret from the masters of cultural critique, no matter how much they try to talk it down from its intolerable, allegedly undemocratic aloofness.

Monday Poem: Olaf

Olaf came to the edge of the water
he knelt he drank the trees leaned in
closer the minnows darted away
from Olaf’s hands and the ripples spreading

Olaf washed his wounds brittle with rust
midges joined him at the edge of the water
he stretched he sighed the trees leaned back
in the wind he tore strips of his clothes for bandages

Olaf reviewed his equipment
his map was torn
he had lost a buckle
his hunting blade was loose in its handle

night came on at the edge of the water
Olaf lay down at the foot of the trees
he shut his eyes minnows darted behind the lids
dreams came humming across the water

Validation in Octarine

A Record  in Octarine is a heterogeneous map, whose keys carry type information about their values. The only type guarantee you get is that if a Record  contains a Key<T> , then the value pointed to by that key will be of type T:

Some additional safety can be given by validating a Record  against a Schema<T> . If the validation is successful, a Valid<T>  can be obtained, which is a Record  ornamented with a type tag linking it to the schema that validated it. You can then enlist the help of the compiler in ensuring that code that will only work with a Valid<T>  is only ever passed a Valid<T> .

Here’s how it works:

The Person  interface here is never instantiated. It has two purposes:

  1. To act as a holder for the Key s and Schema  associated with Person s
  2. To be used as a type tag identifying Record s that have passed validation as instances of  Valid<Person>

The Schema<Person>  is created from a lambda expression that consumes a record and a consumer of validation errors, to which it can send strings describing any errors that it detects. In the example above, we test for the presence of two keys, and apply an additional test to the value of the “age” key.

You can call Validation::isValid  to find out whether validation has succeeded, and Validation::validationErrors  to get a list of all the validation errors that have been detected. Only if the list of validation errors is empty will Validation::get  return a Valid<T> ; otherwise a RecordValidationException  will be thrown.

The tests for the presence of mandatory keys are a bit cumbersome, so you can use a KeySet  to check that all the keys belonging to Person  are present:

Obviously, the compiler can’t guarantee that validation will succeed, since the tests carried out by the schema are only executed at runtime. However, you can subsequently guarantee that other code will only be passed a record that has been validated, by requiring a type of Valid<T>  rather than just a plain Record . This is how Octarine’s validation provides a bridge between the type-unsafe world of external data, and the type-safe world of your program’s domain model.

opting out of the ordinary human real

%d bloggers like this: