Librarian of Alexandria

2012-08-25

Rubbish and Blatherskite

I'm working on a programming language called Rubbish. It is called Rubbish because it is rubbish. Nobody should use it. I will not use it beyond its simple purpose, which is a personal thought experiment.

If this appeals do you, then learn Lisp instead. All dynamic languages are Lisp with a handful of macros and a modicum of discipline, anyway.

In practice, the Rubbish language will have a handful of built-in types—an integer type, a floating point type, a string or rope or something—but, for our purposes, let's assume it has only two types: variants and functions. These two are the only two currently accounted for in the semantics, which I will type up at some point.

Rubbish is weakly typed, so only values have an associated type; variables can take on any type. The primary data type mechanism is the variant, which are analogous to the tagged sums of strongly typed functional languages except without type guarantees. A variant has an obligatory name, which begins either with a capital letter (e.g. Foo), and an optional tuple of expressions, which are evaluated in sequence and stored along with the tag name. Variants are immutable, so there is no mechanism for changing the tag, the values stored with the tag, or the number of values. (If the values themselves are mutable, then they may of course be changed.)

The only meaningful operations on variants are equality and pattern matching; equality may be seen as a deficient form of pattern-matching. Pattern-matching is the only way of extracting information from a variant. For example:

rsh> my_point := Foo(One, Two)
rsh> my_point = Foo
False
rsh> my_point = Foo(Two, One)
False
rsh> my_point = Foo(One, Two)
True
rsh> match my_point { Foo -> Nullary
                      Foo(x) -> Unary(x)
                      Foo(x, y) -> Binary(y, x)
                      Foo(x, y, z) -> Ternary(z, y, x)
                      _ -> Other
                    }
Binary(Two, One)

We can use them as a cheap and easy way to define the Peano numbers.

rsh> add := fun(x, y):
       match x {
         Zero -> y
         Succ(x') -> add(x', Succ(y))
       }

I plan on eventually implementing user-definable mix-fix operators, so you could eventually write the following:

rsh> _+_ := add
rsh> Succ(Succ(Zero)) + Succ(Succ(Succ(Zero)))
Succ(Succ(Succ(Succ(Succ(Zero)))))

The other type is functions, which are introduced with the fun keyword and take a tuple of arguments. There is another syntax for functions of one argument, and it looks kind of like a hash literal. The definitions of isZero and isZero' below have identical functionality. (Notice that this means match x cases is basically syntactic sugar for cases(x).)

rsh> isZero  := fun(x) ->
       match x {
         Zero -> True
         _    -> False
       }
rsh> isZero' := { Zero -> True
                 _    -> False
               }
rsh> isZero'(Succ(Zero))
False
rsh> isZero'(True)
True

Combine this with the following sprinkling of syntactic sugar:

_._ := fun(f, x): f(x)

And we get the following:

rsh> makePoint := fun(x, y):
       { IsOrigin -> x = 0 and y = 0
         GetX -> x
         GetY -> y
         Add(p) -> makePoint(x + p.GetX, y + p.GetY)
         ToString -> format("Point({0}, {1})", x, y)
         method -> raise MethodNotFound(method)
       }
rsh> a := makePoint(2, 3)
rsh> b := makePoint(4, 5)
rsh> a(IsOrigin)
False
rsh> a.IsOrigin
False
rsh> a.ToString
"Point(2, 3)"
rsh> a.Add(b).ToString
"Point(6, 8)"
rsh> a.Add(makePoint(-2,-3)).IsOrigin
True

While variants can encode data, functions like these can easily encode codata like streams.

rsh> ones := { Head -> 1
               Tail -> nats
             }
rsh> streamMap := fun(f, stream): { Head -> f(stream.Head)
                                    Tail -> streamMap(f, stream.Tail)
                                  }
rsh> nats := { Head -> 1
               Tail -> streamMap(fun(x): x + 1, nats)
             }
rsh> take := fun(num, stream):
       match num {
         0 -> Nl
         _ -> Cs(stream.Head, take(num - 1, stream.Tail))
       }
rsh> take(5, ones)
Cs(1, Cs(1, Cs(1, Cs(1, Cs(1, Nl)))))
rsh> take(5, nats)
Cs(1, Cs(1, Cs(3, Cs(4, Cs(5, Nl)))))

Finally, because of mixfix operator definition, we are free to do some pretty horrific things. I am omitting precedence declaration here because I haven't decided on a syntax for it yet.

rsh> _->_ := _._
rsh> nats->Tail->Head
2
rsh> _<-_ := fun(x, f): f(x)
rsh> Head<-Tail<-nats
2

That's some Rubbish for you. There's one major feature I haven't covered yet, and that's delimited continuations. As I said before, if any of this appeals to you, then you are a horrible human being, but I would recommend a healthy dose of Scheme, ML, or Haskell.

2012-06-15

Insights from Slavoj Žižek

What is the trait you most deplore in yourself?

Indifference to the plights of others.

What is the trait you most deplore in others?

Their sleazy readiness to offer me help when I don't need or want it.

What makes you depressed?

Seeing stupid people happy.

What do you most dislike about your appearance?

That it makes me appear the way I really am.

What does love feel like?

Like a great misfortune, a monstrous parasite, a permanent state of emergency that ruins all small pleasures.

What or who is the love of your life?

Philosophy. I secretly think reality exists so we can speculate about it.

Have you ever said 'I love you' and not meant it?

All the time. When I really love someone, I can only show it by making aggressive and bad-taste remarks.

What is the worst job you've done?

Teaching. I hate students, they are (as all people) mostly stupid and boring.

What is the most important lesson life has taught you?

That life is a stupid, meaningless thing that has nothing to teach you.

Q&A: Slavoj Žižek

2012-05-08

Mendel: The Last Genebender

This is what I'm thinking about as I watch The Legend of Korra, which takes place in the same fictional universe as Avatar: The Last Airbender.

Proposal 1: The Genetic Basis of Bending

There are five alleles: w for waterbending, e for earthbending, a for airbending, f for firebending, and N for no bending. The first four are recessive, i.e. ww is the genotype of a waterbender, aa of an airbender, but a wa displays no bending whatsoever.

The final allele, N, blocks all bending in the person who has it. If two people reproduce, one of whom is ff and the other of whom is NN, then despite one parent being a firebender, none of their children will ever be a bender, because all will exhibit the genotype Nf. N is a dominant allele.

In the original series, Sokka and Katara are both members of the water tribe, but Sokka is not a waterbender while Katara is. Their father Hakoda is not a bender, while their mother Kya is. We can therefore surmise that Hakoda's genotype is Nw, Kya's is ww, and, by Punnett square:

  | N  | w
-----------
w | Nw | ww
w | Nw | ww

Sokka's genotype is Nw, i.e. no expressed bending, while Katara's is ww, i.e. she is a waterbender.

This is consistent with Bolin and Mako in Korra. Bolin is an earthbender and Mako is a firebender, but the two are brothers. Consequently, Bolin must have ee and Mako ff, so both of their parents must be ef:

  | e  | f
-----------
e | ee | ef
f | fe | ff

This analysis seems to fit most of the show.

Proposal 2: Account for Aang's Descendents

Aang has three children: Kya, Bumi, and Tenzin. Kya is a waterbender, Tenzin is an airbender, and Bumi does not bend. Bumi is well-explained by the previous proposal, as his genotype would be aw, a non-bending type. But how to account for the other two?

Let us posit a sixth allele: C is the most recessive allele, and as such enables any other kind of bending. A person with the Ca genotype would be an airbender, Cw a waterbender, and so forth; CN would still be a non-bender. In effect, C enables the other allele to take effect.

Now, we revise our analysis of Sokka and Katara's lineage. Suppose that Hakoda, instead of Nw, were instead NC:

  | N  | C
-----------
w | Nw | Cw
w | Nw | Cw

Now, Sokka's genotype is Nw, while Katara's is Cw. Sokka is still a non-bender, and Katara is still a waterbender. Now Katara reproduces with Aang (Ca):

  | C  | w
-----------
C | CC | Cw
a | Ca | aw

Their children can have one of three possible phenotypes: either airbending (genotype Ca), waterbending (Cw), or neither (CC or aw), giving Tenzin's genotype as Ca. His wife Pema either has a recessive airbending trait, so that their children have aa genotypes, or a C allele, so that their children have Ca genotypes. The latter seems more likely.

Accounting for the Avatar

How do we make room for the Avatar, who can bend all four elements? Above I suggested that Aang's genotype was Ca, which enabled us to make the square for Aang and Katara's children work. But what enables the Avatar to bend all four elements?

Magic. Just magic. Fuck you.

2012-02-28

A Downward Spiral

It is entirely possible that this blog will devolve into the Warren Ellis quoting hour.

Dance like you're stamping on a human face forever, love like you've been in a serious car crash that minced the front of your brain, stab like no one can arrest you, and live like there's no such thing as God.

Warren Ellis

Oh, wait, did I say devolve? I meant evolve.

2012-02-16

Dead Literatures

(And I'm interested, I realise, because I want Network Realism for precisely the same reasons that Moorcock and Stross decry the aesthetisisation of steampunk: because the aesthetisisation of anything is an abdication of its politics, because the aesthetisisation of politics is fascism, and fascism is the opposite of imagination. We have too many dead literatures.)

Starpunk, James Bridle

2012-02-07

Cascading recombinance

Cascading recombinance from Matt Webb

all of this is nothing compared to what will be.

this is early email, rabbit phones. this is technology demo, scoping the terrain and guessing what's going to be

in the future the infosphere will be as aether around us and you'll be able to make hiphopalikes by the dozen in five minutes

every cool thing made today is a dead end. each thing pulls together strands of technology and makes a knot, then leaves it.

but in the future every thing will also be a strand, ready to be knotted. and this'll happen suddenly. there'll be a way to combine and recombine, to mix and match, platforms and media and messages.

one day soon we'll get there, then it'll be a cascading recombinance and everything you play with now will be redundant. but that's okay, because you'll be able to make it yourself like that ><

it's *about* to happen on the www, very very soon now. and as that permeates the collective unconscious, it'll happen in the real world too.

2012-01-31

A Poetic Anecdote

My mother recently wrote a poem warning against eating her food—as she is not known to be a prolific cook—and posted it in the kitchen. It went like this:

He who eats here
Must trust his fate
To please his palate
And fill his plate
Sometimes there is
Sometimes there ain't
I'm not a cook
I like to paint

I responded to this abomination with a poem of my own:

I found the bane of Euterpe
    one dismal winter day
A poem so bereft of skill
    I thought my mind would fray
Into a million tiny threads—
    it would have been more pleasant
Than living with its memory
    as I do in the present.

For in the many brilliant years
    when poems were composed
No single dumb, ungainly fool
    had ever yet proposed
To write a poem with such a rhyme
    to make the muses faint
And throw decorum to the wind
    by rhyming "paint" with "ain't."

2012-01-25

A Brief Moment of Neal Stephenson

Isaac [Newton], though better equipped than Daniel or any other man alive to understand Relativity, showed no interest in his pie—as if being in a state of movement with respect to the planet Earth rendered it somehow Not a Pie. But as far as Daniel was concerned, a pie in a moving frame of reference was no less a pie than one that was sitting still: position and velocity, to him, might be perfectly interesting physical properties, but they had no bearing on, no relationship to those properties that were essential to pie-ness. All that mattered to Daniel were relationships between his, Daniel's, physical state and that of the pie. If Daniel and Pie were close together both in position and velocity, then pie-eating became a practical, and tempting, possibility. If Pie were far asunder from Daniel or moving at a large relative velocity—e.g., being hurled at his face—then its pie-ness was somehow impaired, at least from the Daniel frame of reference. For the time being, however, these were purely Scholastic hypotheticals. Pie was on his lap and very much a pie, no matter what Isaac might think of it.

—Neal Stephenson, "The Baroque Cycle", Vol. 3: "The System of The World", Book 7: "Currency", p. 457

2012-01-24

G. K. Chesterton on Language

He knows that there are in the soul tints more bewildering, more numberless and more nameless, than the colours of an autumn forest... Yet he seriously believes that these things can every one of them, in all their tones and semi-tones, in all their blends and unions, be accurately represented by an arbitrary system of grunts and squeals. He believes that an ordinary civilised stockbroker can really produce out of his own inside, noises which denote all the mysteries of memory and all the agonies of desire.

—G.K. Chesterton

2011-07-16

Shameful Sparklines

...
getty: I think the deal is men often have to go ▁▂▃▄▅▆▇█▆▃▁ ▂▃▄▅▆▇█▆▃▁
getty: And multiple orgasms would let them go ▁▂▃▄▅▆▇█▆▄▄▅▆▇█▆▃▁
getty: HA! I knew I could somehow represent that concept in Unicode.
getty: Just THINK! While I was doing that, OTHER people were having ACTUAL SEX!