Conceptual Refactoring : Project GeekWeaver

A few years ago I looked at some of the programs I was writing, both for public release and libraries / scripts for internal consumption, and realized that even I was confused.
I needed a new map to understand what I was doing. Hence I came up with Project ThoughtStorms. A quick and dirty overview of what I was up to in this space of wikis, personal information and knowledge management.
I think that helps. I know what I’m up to, with the legacy of my ThoughtStorms UseMod wiki and SdiDesk, my experiments with Smallest Federated Wiki, the new OWL stuff, etc. It’s still a mess, but it’s conceptually “encapsulated” in a single place.
Now I find myself with a similar situation with a number of different tries at some tools to make it easier for me to produce static web-sites. Originally there was GeekWeaver, a way for me to generate static sites quickly and easily from an OPML outline. That was a great idea … except … it got mixed up with my n00bie enthusiasm for Lisp and desire to create a powerful Lisp-like programming language.
GeekWeaver also foundered on two other issues : soon after I wrote it, there were no popular OPML outliner tools. Although Dave Winer has resolved that issue and I have, indeed, used Fargo to author GeekWeaver programs.
The other, more subtle and pernicious issue is that few people want to develop a site from scratch these days. Most people use huge frameworks with not just Javascript, but CSS, LESS etc. It really doesn’t make sense to try to use a tool which denies the file-system or the fact that you’ll want to be working with a large number of external files.
So the next time I needed to produce some quick static pages I went back to the drawing-board and came up with BootDown : a very simple Python script that lets you write text in Markdown and wraps it in a BootStrap / BootSwatch template. It’s the opposite of GeekWeaver, it isn’t trying to be a rich and clever language that lets you define your own templates, it’s just a quick way to take advantage of a lot of templates that already exist.
BootDown adds two things to conventional Markdown. A shorthand for declaring div tags. And a page separator. So you can still make a multi-page site inside a single file. And you can explicitly reference the div classes and ids you need.
More recently still, I’ve been getting into a real Lisp : Clojure. Today, that’s the language I really want to be working with. And I have a current project that again involves generating a multi-page, fairly static site. But the inputs are a little bit more complicated : some more structured data, not just text. And it makes sense to store it in an outline. So I’ve started writing Clojure code to read OPML and spit out a BootDown Markdown file, to wrap in HTML.
I can see this project starting to grow too.
And so here I am … three Python code-bases : GeekWeaver, BootDown and the OWL back-end server. Two Clojure projects : the beginnings of a library to work on OPML outlines (OPMLKit) and my unreleased code I’m writing for this current project. And some clunky pipelines to use them together. It’s starting to be another mess. And that’s why I need Project GeekWeaver : an umbrella to pull together these different strands together, at least conceptually.
There are some thoughts … would it make sense to pull at least some of the original GeekWeaver code INTO the OWL back-end server? So that “run transformations on this outline” is a standard OWL feature, and OWL becomes GeekWeaver’s built-in IDE? But what about the OWLdroid version that doesn’t have Python? Should I rewrite that code in CoffeeScript. (Or ClojureScript … a working but still fairly slow option at the moment.) BootDown “just works”. Am I better off scrapping the GeekWeaver idea altogether and just focusing on such practical solutions?
Some of this will become clearer as I work through this current site I’m making. meanwhile Project GeekWeaver is the category and (shortly) the site for the high-level overview.

Clojars : A Note

Further to this story.
I tried to deploy another small Clojure library to Clojars today. And found myself being asked for the passphrase to sign my update.

You need a passphrase to unlock the secret key for
user: “phil jones
2048-bit RSA key, ID XXXXXX, created 2012-03-05

I got into a terrible confusion. Because, for the life of me, I couldn’t remember what passphrase I’d chosen to sign my Clojar last time. Had I just locked myself out of my Clojars account and the existing group and Patterning project?
A couple of hours faffing and I figured it out :
– my previous library WASN’T signed. It’s just in “Clojars Classic” and isn’t “promoted” so doesn’t require signing. That’s why I don’t remember signing it or inventing a pass-phrase.
– the reason that lein deploy was demanding a pass-phrase THIS TIME, was that in this library I’d decided to remove the word SNAPSHOT from the id in defproject.
lein deploy assumes that SNAPSHOTs default to being deployed in classic (the “free-for-all” part of Clojars) whereas non-SNAPSHOTS are intended to be deployed in the new “releases” repository, which is slightly more formalized arrangement, requiring author signing.
– I have gpg on my machine, and I did set up signing for my email address a couple of years ago. This was nothing to do with the previous library I put on Clojars. It was when I was experimenting with encrypted email. (A practice that I’ve embarrassingly let slip since then, but should really go back to.) So that’s the pass-phrase that was being demanded, and that I’ve managed to forget (from 2012, not end of 2014). Not impressive, but not quite as bad as creating one four months ago and then totally forgetting about it.
That still leaves me with some problems when I eventually will want to put my libraries into “releases”) but at least I can still use Clojars. The library will have to continue as a SNAPSHOT though.

Welcome to 2015 (part 2)

Bloody hell! I just wrote a blog post and WordPress lost it.
Grrrr …
The short resume was :
– yes, I’m late (Feb) continuing my “Welcome to 2015” blog posts.
– last year I got the functional programming bug. Haskell is pretty damned good, but I’ve fallen for Clojure because a) dynamic types, b) Lisp syntax(lessness), c) Paredit.
– last year I did more Python, but not much OWL. This year, OWL is calling again. And as well as making me want to rethink Mind Traffic Control in light of it, is also seeming to demand some kind of pivot on GeekWeaver.
I’ll be coding and blogging more on this ongoing development in coming weeks / months.
I’ve also been playing a bit with remoteStorage, but nothing to show yet.

Clojars

Well that was surprisingly painless.
I’m in the process of reorganizing the code for Patterning, my Clojure library that produces (visual) patterns.
Patterning was built using Quil, which is a Clojure wrapper around Processing. But I wanted to be able to call the library directly from Processing itself (Java version).
It seemed silly to create an uberjar file containing the whole of Quil and Processing, to be called from … er … Processing, so I decided to split the project into the core (pure Clojure, no Quil or Processing dependencies) and a Quil based wrapper.
I’m also, compiling the library using ClojureScript to run in the browser. (Called from Javascript). Once again this part doesn’t want any Quil / Processing dependencies.
But I was a bit stumped with how to manage some of this. My previous experience of projects that rely on other projects (git submodules) has been somewhat painful.
But it seems the Clojure (via Java) world has actually sorted this. All I needed to do was create an account over on Clojars and type :

lein deploy clojars

to put the JAR for my Patterning library there.
And so here it is.
Including it in a new project is as simple as referencing it in the project.clj file. There’s a simple test project which combines both Patterning and Quil. And here’s the very simple project.clj file. Note the patterning dependency.

(defproject com.alchemyislands/patterning_quil "0.1.0-SNAPSHOT"
    :description "Quil Wrapper for Patterning library"
    :url "http://alchemyislands.com"
    :license {:name "Eclipse Public License"
    :url "http://www.eclipse.org/legal/epl-v10.html"}
    :dependencies [[org.clojure/clojure "1.5.1"]
                   [org.clojure/math.numeric-tower "0.0.4"]
                   [quil "1.7.0"]
                   [com.alchemyislands/patterning "0.3.0-SNAPSHOT"]]
    :aot [patterning_quil.core]
    :main patterning_quil.core
)

And that’s more or less it.
If you want to use Patterning in your own projects, just include it like that. If you still want to be using Quil, then use this as your example.
BTW: the new development for the core Patterning library is now at https://github.com/interstar/Patterning-Core

Clojure Multimethods

Wow! Now this is weird!

I honestly don’t know what to make of Clojure’s ad-hoc hierarchies. I have, I confess, been missing a little bit of the polymorphism I’m used to with classic OO class-hierarchies.

This looks like it’s the answer to that. But hmmmm …. if I start down this path am I going to find myself reinventing standard OO capacities with a weird syntax? Does adopting these things mean I’m falling back from my FP sophistication to “class-based” programming? Is it the equivalent of abusing do to make my Lisp more imperative?

Lazy Lists Are Late-Binding

A thought that struck me in the swimming pool today.
Lazy lists are another kind of late-binding.
Everyone hypes lazy lists by saying “wow! you can even have infinitely long lists!”
To which the natural response is, “So what? The universe is finite and my life and this program are certainly finite, why should I care?”
But, instead think about this. “Infinite lists” are really “unbounded lists” are really “when you create them, you don’t know how long you want them to be” lists.
It’s another part of the program, the “consumer” of the list, which knows how long you want them to be.
For example, I’m currently generating patterns in Clojure + Quil. Here’s one which is basically formed by filling a grid with a number of tiles.
Patterning
The important thing here is that, although I know I want a repeated pattern of different tiles, I don’t need to know how many of these tiles in total I’m actually going to need to fill my grid, so I just create an infinite list, using
(cycle [tile1 tile2 tile3 tile4])
Then I have a function which zips the list of tiles with a list of positions to be filled. The list of tiles is infinite, but the list of positions on the grid isn’t, so the zipping ends up with a finite grid of tiles.
In a sense, this is yet another example of “late-binding” (ie. leaving decisions as late as possible). It allows the names of data-structures to stand for things (data-structure) whose shape and extent is determined much later.

Are Languages Still Evolving Towards Lisp?

My Quora answer to the question “Is it still reasonable to say mainstream languages are generally trending towards Lisp, or is that no longer true?

Based on my recent experiments with Haskell and Clojure.

Lisp is close to a pure mathematical description of function application and composition. As such, it offers one of the most concise, uncluttered ways to describe graphs of function application and composition; and because it’s uncluttered with other syntactic constraints it offers more opportunities to eliminate redundancy in these graphs.
Pretty much any sub-graph of function combination can be refactored out into another function or macro.
This makes it very powerful concise and expressive. And the more that other programming languages try to streamline their ability to express function combination, the more Lisp-like they will get.
Eliminating syntactic clutter to maximize refactorability will eventually make them approximate Lisp’s "syntaxlessness" and "programmability".
In that sense, Paul Graham is right.
HOWEVER, there’s another dimension of programming languages which is completely orthogonal to this, and which Lisp doesn’t naturally touch on : the declaration of types and describing the graph of type-relations and compositions.
Types are largely used as a kind of security harness so the compiler or editor can check you aren’t making certain kinds of mistakes. And can infer certain information, allowing you to leave some of the work to them. Types can also help the compiler optimise code in many ways : including safer concurrency, allowing the code to be compiled to machine-code with less of the overhead of an expensive virtual machine etc.
Research into advanced type management happens in the ML / Haskell family of languages and perhaps Coq etc..
Ultimately programming is about transforming input data into output data. And function application and composition is sufficient to describe that. So if you think POWER in programming is just about the ability to express data-transformation, then Lisp is probably the most flexibly expressive language to do that, and therefore still is at the top of the hierarchy, the target to which other programming languages continue to aspire.
If you think that the job of a programming language is ALSO to support and protect you when you’re trying to describe that data-transformation, then POWER is also what is being researched in these advanced statically-typed languages. And mainstream languages will also be trying to incorporate those insights and features.

Clojure

OK. Consider me won over.
Lisp is great to work with. The things that grabbed me about FP in Erlang and Haskell (pattern-matching arguments, partial application, lazy evaluation) are all here.
My code is as concise as Erlang and damned nearly as concise as Haskell (I think the line count is similar though the number of characters per line is about twice as high)
Although I respect Haskell’s type system, Clojure’s dynamic typing holds me up less. I *am*, admittedly, hitting more problems that a type system would have picked up. (Far more than I typically hit in Python) but I think as I get more used to the language this will go down.
I’m not being particularly demanding in terms of libraries. (Quil is almost all the libraries I need at the moment.) But I’m finding that there are all these handy things like spit which make me smile. (Remember what this was like in Java?)
Things that would still be a bit fiddly in Python / CoffeeScript continue to turn out to be easier than I imagined they would be when I implement them in Lisp. That’s partly because I default to approaching them as “how do I write a small lambda that can then map across this list” and mostly, by the time I wrote that function, all I have to do is … er … map it across the list.
Lisp is extra-ordinarily compressible. I keep finding ways to refactor and fold up things I did earlier to make them shorter and shorter. And the more functionality I add to my program the more compressed it seems to get.
I am grinning to myself at the thought that my code might be compilable to both Android and into Javascript. I haven’t tried either yet, but if I manage it then Clojure is now my new favourite language.
CoffeeScript isn’t at all bad, but if ClojureScript works out, then I’ll probably start to move aggressively to use it as my default in-browser language. (And yes, I guess that may mean rewriting OWL in it. OWL is still short enough that I think I could sprint it in a couple of days.)
Similarly, if I can compile Clojure libraries that can be called from Java projects then you’ll start to see me more productive on Android. (Beyond OWLdroid I have a couple of other bits and pieces of apps. written, but not taken them to completion. If Clojure slots painlessly into the workflow, it will be a lot more tempting to dive back in.)
So … yeah … Clojure rocks!

Clojure Debugging

Has to be said that Clojure’s runtime debugging support is the worst ever. A call stack of irrelevant Java information and no idea which line of Clojure actually triggered the error.
At least with CoffeeScript you can look into the Javascript at the appropriate line-number and see sort of what it’s doing and then map that back to CoffeeScript manually.