| (no subject) |
[May. 26th, 2012|08:19 pm] |
I chatted with Sean today for a while and he left me with a cute types puzzle. The puzzle is, assign types to the ?s in the signature
sig
val blank : ?
val binop : (int * int -> int) -> ?
val unop : (int -> int) -> ?
val const : int -> ?
val eval : ?
end
and implement it in a structure S such that the following makes sense:
open S
(* expression with holes: [ ] + (~[ ] + (2 * [ ])) *)
val f = eval (binop (op+) blank (binop (op+) (unop (op~) blank) (binop (op *) blank (const 2))))
val _ = print (Int.toString (f 100 2 3000)) (* prints 100 + (~2 + (2 * 3000)) = 6098 *)
val _ = print "\n"
What's going on here is f builds up an expression tree out of binary and unary operators and integer constants and blank holes, calls eval on it, and this has the type int -> int -> int -> int which is a curried type with three integer arguments, equal to the number of occurrences of "blank" in the definition of f.
But how can you get eval to have a type that always has one curried argument for each blank, and in fact evaluates the right expression? ( my solution; spoilers! ) |
|
|
| (no subject) |
[May. 25th, 2012|07:21 pm] |
The awesomest kind of performance bug is when you realize it's taking a long time to render an image because you're accidentally rendering it all over again once per pixel in the image. Nothin' like a good ol' O(n4) algorithm. |
|
|
| (no subject) |
[May. 24th, 2012|02:01 pm] |
Watched some more Freaks and Geeks with K. There was a great moment where the nerd heroes of the show triumphantly did a Successful Sports Thing (i.e., caught a fly ball, yielding one out) --- but only one such thing. Which was nice, because it was more realistic than Winning The Entire Important Sports Game. |
|
|
| (no subject) |
[May. 23rd, 2012|09:10 pm] |
If you haven't read this long and winding road towards the smallest possible ELF binary (45 bytes!) you really should. It's a classic from like 2002 or something. |
|
|
| (no subject) |
[May. 22nd, 2012|09:07 pm] |
Dinner with K at the mexican place across the street from work. Yucateco continues to be tasty, but just a little too spicy for me to handle. |
|
|
| (no subject) |
[May. 21st, 2012|08:42 pm] |
Jonesforth is a very small forth interpreter written in about ~2k lines of x86 asm and ~2k lines of forth. The asm is actually overwhelmingly comments, with lovingly drawn ascii-art memory diagrams. It's a wonderful piece of literate programming.
You only really need the two files jonesforth.S and jonesforth.f, and then you do
$ gcc -m32 -nostdlib -static -Wl,--build-id=none -o jonesforth jonesforth.S
$ cat jonesforth.f - | ./jonesforth
and you're good to go. Try typing
2 3 + . and you should get [SPOILER WARNING!] 5.
The instructions in jonesforth.S itself say to also include the flag "-Wl,-Ttext,0" but when I do this, I get "Killed" immediately upon running ./jonesforth. Even when I gdb and breakpoint at _start. Anybody know why? Does this have to do with address space randomization or something? |
|
|
| (no subject) |
[May. 20th, 2012|09:06 pm] |
Another pixel doodle:
 |
|
|
| (no subject) |
[May. 20th, 2012|08:42 pm] |
Puttering around home today tidying up and doing some errands. |
|
|
| (no subject) |
[May. 19th, 2012|08:26 pm] |
Food adventures today consisted of: (1) Went to Jolie Cantina for brunch. Had awesome omelet with bacon, ham, shallots, spinach. (2) Made chicken vindaloo again, this time with toasted naan instead of rice. Also awesome. |
|
|
| (no subject) |
[May. 18th, 2012|08:25 pm] |
Saw the opening of Indie Game - the Movie over at IFC with K. Basically the filmmakers embedded themselves in the development of Super Meat Boy and Fez, and there was also some interview footage with Jonathan Blow ("Braid"). One thing that really came across (and I found it rather comforting) was how much even the people who are widely understood to be at the absolute top of their field are still completely capable of being all but consumed by anxiety about their past, present, and future work. I think they did a great job of painting a very human picture of the developers. |
|
|