Madoko Blues

Madoko is a very cool set of Markdown extensions/tools for writing full fledged academic “stuff” in Markdown. It compiles to HTML and LaTeX (of course!) and really has a lot of cool stuff. It supports reveal.js and beamer presentations in what seems to be a nice way.

In general, it feels like a win.


It was developed as a demonstration for the Koka language. Koka is a nice enough looking experimental language which compiles to Javascript. Ok. So any bug fixing or tweaking requires learning a new language. Ok. Well, what does it take to get started? Only this:

First install some pre-requisites:

  • Install TortoiseHg for mercurial version control.
  • Install the Haskell Platform to build the compiler (version 7.4 or later).
  • Install Node for running Koka programs (version 0.10 or later).
  • We recommend the excellent SublimeText text editor for developing Koka programs.

Then get the compiler and libraries, and build them:

  • hg clone (clone the Koka sources)
  • cd koka (go to the new Koka directory)
  • npm install (install needed Node libraries)
  • jake (build the compiler and run the Koka interactive environment)

Well you might as well say, “Fuck off”.

Which is a shame because Madoko doesn’t 100% work. I’ve had terrible trouble with Bibtex files and the beamer output is just awful. Often unusable. Well fine, maybe I can live without it, but it’s super frustrating when it’s right there. It doesn’t seem to generate “semantic” beamer, but maybe I can force it to? Maybe it uses templates somewhere? Ugh.

An alternative is to extract a language spec and reimplement it in Python.

(Or I guess Pandoc, but it has a lot of similar pain plus missing a lot of stuff Madoko has.)

Cranky Pants Wirth

I love Niklaus Wirth’s work. I read his compiler constructor book and it was so beautiful and make computer science seem so elegant…it’s why I ask my PhD students about the Chomsky Hierarchy to this day. I thought the Oberon system was very neat (esp the S3 spin off).

But damn he can make a lot of undersupported claims in a short text. “A Plea for Lean Software” is a fun, cranky polemic but the 9 lessons learned are a big pile of “because I say so”. Eg lesson number one is that the speed the “complex” Oberon system was developed depended on having a strong and statically/manifestly typed language. Ok! I’m convinced! Well, no, I’m not convinced 😉 I’m willing to bet that it has a lot to do with having a genius programmer/system designer who could do exactly what he wanted with no compatibility issues or external constraints to face.

I think life and computer science are better now. We know more and more of what we don’t. People still make these gonzo claims but they don’t go quite as far.

I hope.

I still love reading it though.

Are Tuplespaces That Much Better?

I remember reading about Linda (and thus tuplespaces) back in the day and loving it. It seemed really cool, elegant, simple and likely effective way of doing distributed programming. It is really easy to add to existing programming languages. And it essentially never took off. Greg Wilson thinks this is a big loss:

It’s easy, easy, easy for beginners to understand—much easier than MPI. And compile-time analysis of tuple in/out patterns can make it run efficiently in most cases; adhering to some simple patterns can help too. But for a whole bunch of reasons, it never really took off: not as a language extension to C, not as JavaSpaces, not in various homebrew implementations for agile languages like Python, and that makes me sad. It’s as if the metric system had failed, and we had to do physics with foot-acres and what-not. But I guess that’s the world we live in…

Is it really that dramatic? How would we tell? What’s the analysis like?

The thing about tuplespaces is that it is straightforward to add them to just about any system. So….why don’t people who know about them just use them?

This just might be a good MSc project!

Rockstar Rainfall Problem

I had to write a Rockstar program. FizzBuzz was done so I decided to try the Rainfall Problem:

Write a program that will read in integers and output their average. Stop reading when the value 99999 is input.

Here’s my program:

My hopes are nothing
The future is nothing without my hopes

Listen to the sky
Until the sky is decimated, destroyed; sparkling, sinuously perfected
Build my hopes up
My dreams are the sky with the future
They are my dreams
Listen to the sky

If my hopes ain't nothing
shout the future over my hopes

If my hopes are nothing
whisper the future of my hopes

It’s damn tricky! The first block initialised the counter (my hopes) and the sum (the future) to zero (nothing). I subtracted zero from zero for the second line to add a little variation.

Getting 99999 so it would scan and make sense was very hard. I don’t think it quite worked, but it’s not an unbearable stretch. Rather too much alliteration.

The averaging sounds a bit odd. I did guard against no input, yay!

Unfortunately the Python transpiler isn’t very complete. Here’s the raw output:

my_hopes are False
the_future = False - my_hopes
the_sky = input()
while not the_sky == decimated, destroyed; sparkling, sinuously perfected:
    my_hopes += 1
    my_dreams are the_sky + the_future
    They are my_dreams
    the_sky = input()
if my_hopes != False:
    shout the_future / my_hopes
if my_hopes are False:
    whisper False

So, it doesn’t understand are or nothing properly and doesn’t handle poetic number literals. Easy enough to hand fix:

my_hopes = 0
the_future = 0 - my_hopes
the_sky = int(input())
while not the_sky == 99999:
    my_hopes += 1
    my_dreams = the_sky + the_future
    the_future = my_dreams
    the_sky = int(input())
if my_hopes != 0:
    print(the_future / my_hopes)
if my_hopes == 0:

Note that since Python 3.x replaced input with raw_input (and threw away Python 2.x’s input, I had to add a manual cast around the read. I think the semantics of Rockstar’s listen has to be more like old input otherwise you couldn’t input numbers.

Anyway! There you go!

(I didn’t filter negative numbers since the problem as stated in the linked paper puts that as an elaboration. That would be a PITA to handle :))

It’s clear that there needs to be more synonyms and esp “null” words i.e., words which just get dropped.

The Rockstar Programming Language


I mean check out the FizzBuzz example:

Midnight takes your heart and your soul
While your heart is as high as your soul
Put your heart without your soul into your heart

Give back your heart

Desire is a lovestruck ladykiller
My world is nothing
Fire is ice
Hate is water
Until my world is Desire,
Build my world up
If Midnight taking my world, Fire is nothing and Midnight taking my world, Hate is nothing
Shout "FizzBuzz!"
Take it to the top

If Midnight taking my world, Fire is nothing
Shout "Fizz!"
Take it to the top

If Midnight taking my world, Hate is nothing
Say "Buzz!"
Take it to the top

Whisper my world

Here’s that code run through a Rockstar to Python transpiler:

def Midnight(your_heart, your_soul):
    while your_heart >= your_soul:
    your_heart = your_heart - your_soul
    return your_heart

Desire = 100
my_world = False
Fire = 3
Hate = 5
while not my_world == Desire:
    my_world += 1
    if Midnight(my_world, Fire) == False and Midnight(my_world, Hate) == False:
    if Midnight(my_world, Fire) == False:
    if Midnight(my_world, Hate) == False:

That’s not bad! Of course, changing the problem definition from “FizzBuzz” to “Fuck you” is waaaay more rock n’ roll (and funny).

Interestingly, the “minimal Rockstar” version (i.e., using only basic features and programming oriented variable names) isn’t terrible:

Modulus takes Number and Divisor
While Number is as high as Divisor
Put Number minus Divisor into Number
(blank line ending While block)
Give back Number
(blank line ending function declaration)
Limit is 100
Counter is 0
Fizz is 3
Buzz is 5
Until Counter is Limit
Build Counter up
If Modulus taking Counter, Fizz is 0 and Modulus taking Counter, Buzz is 0
Say "FizzBuzz!"
(blank line ending 'If' Block)
If Modulus taking Counter and Fizz is 0
Say "Fizz!"
(blank line ending 'If' Block)
If Modulus taking Counter and Buzz is 0
Say "Buzz!"
(blank line ending 'If' Block)
Say Counter
(EOL ending Until block)

Indeed, it’s basically verbose Python.

My favourite part is the “poetic” syntax for number literals. This is where the magic happens:

A poetic number literal begins with a variable name, followed by the keyword is, or the aliases was or were. As long as the next symbol is not a reserved keyword, the rest of the line is treated as a decimal number in which the values of consecutive digits are given by the lengths of the subsequent barewords, up until the end of the line. To allow the digit zero, and to compensate for a lack of suitably rock’n’roll 1- and 2-letter words, word lengths are parsed modulo 10. A period (.) character denotes a decimal place. Other than the first period, any non-alphabetical characters are ignored.

That’s crazy! Consider the first example: Tommy was a lovestruck ladykiller. Tommy is the variable, was is an alias for the assignment operator. The rest of the line is a numeric literal. a has length 1, so it represents the digit 1. lovestruck and ladykiller each have length 10, so given that 10 mod 10 is 0 each represent a 0. Thus the whole line assigns 100 to Tommy.

Love it!

It’d be interesting to design a folk variant.