1. 14
  1.  

  2. 7

    [My comment on reddit might be interesting to some]

    Quick author’s note. I didn’t talk about the runtime system because frankly I don’t care that much about it but the way we calculate the fixed point of a closure is pretty cool.

    It’s a method called “back-patching”. The idea is that you get a closure so you have a C function which takes a bunch of pointers and returns a pointer. So what you do is create a pointer and don’t fill in the value yet.

    You then apply the function you’re finding the fixpoint of and get the result. This result is incomplete though because it contains a pointer to garbage. We want that pointer to be the recursive call. To do this you set the value of the pointer you passed in to the result. This “patching” actually gives you a fixed point.

    In order to make this work in C there’s some pain but it’s actually not so terrible. The pain is just ensuring that no one actually tries to read a pointer that hasn’t been patched yet.

    edit: Of course there was a bug in one of those lines (shakes fist at sky damn you C).