Curiouser and Curiouser!

'Where shall I begin, please your Majesty?' He asked. 'Begin at the beginning,' the King said, very gravely, 'and go on till you come to the end: then stop.'

Thoughts on a different kind of thinking & writing space

It was a throw-away thought while I had Facebook open but I had this idea about a writing space that breaks the strict reverse-chronology of blogging and is instead like a note book but also a shared notebook in terms of bi-directional links to other notebooks and one that dynamically weaves relevant content from other notebooks maybe by inclusion, quotation, or referencing.

But thinking back to the 1990 documentary Hyperland (if you remember that far back) where rather than something being deemed relevant and "sitting there", as so often happens, it's more offered to you and your decision about whether it's interesting/relevant or not feeds into some parallel process that mirrors your own writing/thinking.

So the process is dynamic process both in terms of content but also in terms of interaction.

If this were to be interesting I think it's somehow because of whatever function decides relevance over time and content.

This feeds into a history of ideas I've had, going back almost 20 years, about creating some kind of intelligent notebook. I'm quite interested in the idea of maybe publishing these kind of notebooks as "brains" via Git so as to allow them to be versioned, branched, merged and so on.

One day I'd like to be able to build such a thing...

05/04/2014 13:29 by Matt Mower | Permalink

A moment of connection

On Republique station a middle-aged Chinese gentleman was playing the flute and a strange instrument like a hexagonal violin.

I wanted to give him something but being both intimidated by the Parisiens and embarrassed to find maybe €0.50 in my pocket I waited until the train arrived before walking over and dropping it in his case, then heading for the train.

As I sat down I glanced back at the man who looked up just then and, nodding at me, smiled. I smiled back although I became suddenly self-conscious.

I persuaded myself to look again and he met my gaze and smiled again, a warm smile, as he bent to his playing.

I could so easily have bowed to my fear and given him nothing and, worse, missed this momentary connection with another human being and playing that we both enjoyed.

(~2007)

12/03/2014 11:06 by Matt Mower | Permalink
More about:

Juxt a minute

Caveat lector: skip if you're not interested in the experiences of someone learning Clojure and functional-programming.

At the moment I am reading the excellent Clojure Programming from O'Reilly. It was one of the first books I bought but I found it a little formidable as an introduction to Clojure. I'm finding it a lot more digestible now.

In it I came across an example of the excellently named juxt function. Reading the docs I found it a little difficult to get my head around:

Takes a set of functions and returns a fn that is the juxtaposition of those fns.  The returned fn takes a variable number of args, and returns a vector containing the result of applying each fn to the args (left-to-right).

It's actually really simple but the use of the word juxtaposition made me think it more complicated than it is. To whit:

juxtapose (verb) place or deal with close together for contrasting effect: black-and-white photos of slums were starkly juxtaposed with colour images.

But what was the contrasting effect?

The O'Reilly example was:

(juxt quot rem)

as a replacement for:

(defn euclidian-division [x y]
    [(quot x y) (rem x y)])

and, as I played with the output of the function, the penny starts to drop. Then I see it, that the contrast, the juxtaposition, is in how each of the functions passed to juxt interprets its argument(s).

It seems to me that juxt is like a map generator. But where map is about mapping a function across a sequence of values, juxt returns a function that maps a sequence of functions across its arguments.

So now I felt I understood it but I wondered how I could make use of it myself. I use map all the time but in what circumstance do you need to apply a series of functions over a value?

In calculating the value of a polynomial the degrees are, essentially, functions of an argument x where x is raised to the degree and multiplied by a constant, e.g.

2x2,3x1, or -1x0

The result of each of these degree functions is summed to get the total value of the polynomial for x. In Clojure terms we could say this is summing the juxtaposition of the degree functions which might look a bit like:

(defn polynomial [& degrees]
  (comp (partial apply +) (apply juxt (map-indexed (fn [degree multiplier]
             (fn [x]
               (* multiplier (Math/pow x degree)))) (rseq (vec degrees))))))

polynomial is a function that takes as it's arguments the constant multiplier of each of the degrees of a polynomial starting with the highest and ending with the power zero. It returns a function that takes an argument x and returns the value of the given polynomial for x.

So:

# Calulate the value of the polynomial
#   2x^2+3x-1
# where x = 3
((polynomial 2 3 -1) 3)
# => 26.0

I use juxt to create a function that takes an argument and return a sequence of values obtained by passing the argument to each of a sequence of anonymous functions that calculates the value of one degree of the polynomial:

(fn [x] (* multiplier (Math/pow x degree)))

I then use comp to compose the function returned by juxt with a function that sums the individual components to give the total value for the polynomial at x.

I'm quite happy that I understand juxt, found a reasonable way of using it, and also managed to get comp in there too!

Update: Marshall Bockrath-Vandegrift (llasram from the #clojure IRC channel on Freenode) came up an alternative implementation using ->> threading macro to pull the function pipeline inside out, replacing the more cumbersome (rseq (vec degrees)) with (reverse degrees) and using Clojure's anonymous function literal syntax #(..) instead of (fn ..).

(defn polynomial
  [& degrees]
  (->> (reverse degrees)
       (map-indexed (fn [i m] #(* m (Math/pow % i))))
       (apply juxt)
       (comp (partial apply +))))

I think this one is more readable and probably more idiomatic clojure. Thanks llasram.

05/02/2014 16:00 by Matt Mower | Permalink

Not quite forevernote

I've recently allowed my Evernote premium subscription to lapse. Here's why.

When the date of my renewal arrived, Evernote sent me a somewhat brusque "Thanks and goodbye" email telling me about how I'd been downgraded and lost a bunch of features.

I'd been in two minds about renewing right up until the deadline. Perhaps a softer approach, maybe even offering me another week or so to think about it, might have won me over. Alas, we'll never know.

The reason I was having so much trouble justifying the renewal is the vast gulf between Evernote the concept and The Evernote application.

The concept of having all your information organised in notebooks that can be shared and synchronised across all your devices, even shared with other people, is a compelling one.

But there are just so many areas where it doesn't work right that a great concept is translated into an application I ended up resenting.

For me the most essential are:

  • The editor is rubbish
  • Sharing is a minefield
  • The security story is straight out of the "How not to do it" playbook
  • It's dumb, no scripting, no smarts
  • You'd be forgiven for thinking one dev works on it every other weekend

The most pressing of these is the editor. For an application that is all about authoring text, the writing environment is appalling. In the Mac version there are no headings and you can't even indent text!

And worst of it is that it's just HTML. There are free HTML editors leagues ahead of this. It really is a dismal experience and they show no signs of improving it at all. It certainly hasn't improved in the 15+ months I've been using it.

Sharing notebooks is a killer feature. And it works, more or less, providing you don't need anyone else to change anything. Because if you do you will often get bizarre conflicts and stuff will get deleted or overwritten. With careful management it's possible to work together but inexperienced users are always going to get tripped up and who needs this much hassle?

Once you start putting valuable info in there you'll wonder about Evernotes security. Only it doesn't have any. Everything is in the clear. Unless you use encryption on a page-by-page basis. Only you won't because it's so painful to do.

Then again with all this information in it you'd Evernote to be really smart. To help you make connections, maybe even to be a base for user-scripts.

But no, Evernote is dumb. While they do have a web API for capturing content there's nothing for the app itself. When I think of Tinderbox and it's agents and, well, really I shall just stop here because it's sad how stupid Evernote is. And don't get me started "related" pages.

Lastly I guess we come to the final nail in the coffin: I have lost all hope that any of these shortcomings will be addressed.

In the 15 months I have been a premium subscriber the application has not improved in any area that I care about. That the editor has not improved is baffling beyond my ability to comprehend. I cannot reward such developers with my money or my attention.

So I shall be bidding Evernote goodbye over the next month or two. I'm not sure yet what I will use to replace it. I could go back to VoodooPad which is in new hands and may see some evolution but is, anyway, pretty good.

I've also been pondering the lessons of LightTable and considering building something myself using ClojureScript, node-webkit, and Dropbox.

But I've been here before and I'm not sure I have the skill & dedication to take on such a major undertaking on my own.

More later I guess.

01/02/2014 01:12 by Matt Mower | Permalink
More about:

Can't close. Won't close.

Okay so, like most of you, I perpetually have anything from 10 to 10^30 open browser tabs. This starts to become a problem when Safari is consuming all the memory in my computer and starting to chew through the disk as well.

At that point I am presented with the problem of how do I close some of these tabs. And it is a problem because I know of only two strategies:

  1. Bookmark the page URL in Pinboard to read later
  2. Read the page

I like strategy 1, I use it often, but I have to acknowledge that Pinboard is pretty much where I send pages to die.

So any page that I'm not reasonably confident I do actually want to read goes to Pinboard to wait for that mythical day when I go back and read all my pinned pages.

And that leaves me with a whole bunch of tabs and strategy 2.

But here's the problem with strategy 2 beyond actually having to read this stuff:

In any page interesting enough for me to read it I invariably find links to at least two or three (and often more!) other pages that I want to read.

So I manfully struggle through closing 3-4 tabs only to find I now have something like a dozen more than I started with! And Safari slower than ever.

No it makes no sense to try and close browser tabs.

30/01/2014 17:41 by Matt Mower | Permalink
More about:

Todays Clojure mind bender

You want the nth element of a collection, for example the 5th element of [a b c d e] or the third maybe.

How about this as a solution (from the excellent Joy of Clojure):

(defn fnth [n]
  (apply comp
    (cons first
          (take (dec n) (repeat rest)))))

((fnth 5) [a b c d e])
=> e

At first glance my brain wouldn't wrap itself around this function. That's my brain really coming to grips with first-class functions.

What it does is to construct (for n=5 say) a list:

'(first rest rest rest rest)

Then it uses apply to turn that list into arguments the comp function. comp takes as its arguments a list of functions and returns a new function which is their composition. In this case:

((comp first rest rest rest rest) list)

is equivalent to

(first (rest (rest (rest (rest list)))))

Which returns the 5th element of list.

It's a kind of meta-programming that isn't macros.

Mind bent!

24/01/2014 19:20 by Matt Mower | Permalink
More about:

Clojure power-ups

A few Clojure libraries I am making use of:

What print-foo does is provide a library of debugging macros for printing useful info.

So for example you have the very complicated function:

(defn adder [m n] (+ m n))

The adder function is being invoked and you'd like to see the arguments and return value. Normally this would involve instrumenting the function with println statements. However by using the print-defn macro:

(print-defn adder [m n] (+ m n))

whenever adder is called it will print the values of m, n, and the return value of adder to the console.

Instarepl:  m 5
Instarepl:  n 6
Instarepl:  defn 'adder' result: 11

Handily there are equivalent forms for if, cond, let, and the threading macros -> and ->>.

Have to say I am very happy to see Jay Fields in the Clojure world, I always found he made a huge amount of sense talking about Ruby.

Expectations is a testing library. I didn't hit it off straight away with core.test and then watched a video of someone testing with Expectations and I was off to the races.

The library is based around a single expect function (or, more likely, macro). Something that's great about expect (and maybe core.test does this too, I don't know) is the degree to which it helps you when things fail. For example:

failure in (core.clj:18) : sample.test.core
       (expect {:foo 2} (in {:foo 1, :cat 4}))
       expected: {:foo 2}
             in: {:foo 1, :cat 4}
       :foo expected: 2
                 was: 1

The degree to which it figures out what exactly is wrong is really helpful. I haven't explored it much more than this but already I am finding myself testing more and more.

I've only just started to use this library but it provides some powerful tools for data validation and Clojure is all about the data.

(def Data
  "A schema for a nested data type"
  {:a {:b s/Str
       :c s/Int}
   :d [{:e s/Keyword
        :f [s/Num]}]})

(s/validate
  Data  
  {:a {:b "abc"
       :c 123}
   :d [{:e :bc
        :f [12.2 13 100]}
       {:e :bc
        :f [-1]}]})
;; Success!

In a statically typed language I guess you wouldn't need such a thing. So far I prefer dynamic typing with something like Schema to check things where I need to (so far, usually in my expectations)

I guess that's enough for now. There's other things I am playing with like core.async which a lot of other people are writing about, and far better than I could, and more esoteric stuff like Clojure-Lanterna (a library for creating console GUI's based on the Java Lanterna library).

What Clojure goodies have you found?

23/01/2014 09:59 by Matt Mower | Permalink
More about: