Stalled SECD Work
Being the ongoing but abridged saga of a translation of a deconstructed
abstract machine (interpreter) for a fairly basic lambda calculus, due to
Peter Landin (the original 1964 SECD machine) and Olivier Danvy (the 2003
deconstruction), said translation starting with SML, detouring through
Ruby, and stalling out for no intrinsic reason with a partially working
OCaml version.
In our last episode (May 2007) I
wrote: "The machine part compiles; maybe I'll be able to
get the test app running later this week."
It being July now, that'd have to be a heck of a week.
Fact is, I've been finding precious little time to work
on it, with some major deadlines at work and other
personal issues intruding.
But I do recall that I never put the OCaml version up anywhere,
and since I haven't even touched it in over three weeks, I figured
it must be time to put it up here so I can find it later.
Caveats: I've only compiled it on my old Mac at home, with
Ocaml version 3.06. And it's not fully debugged yet, either.
But it does say helpful stuff like this:
Evaluate 0 ...
Evaluating <LIT 7>
result 7
Evaluating <LIT 3>
result 3
Evaluating (\x -> [succ _ x])
result (E:<[ succ =succ
]>, V:x, T:[succ _ x]:)
Evaluating [(\x -> [succ _ x]) _ <LIT 8>]
result 9
Evaluating (\x -> (\y -> [succ _ x]))
result (E:<[ succ =succ
]>, V:x, T:(\y -> [succ _ x]):)
Evaluating [(\x -> [succ _ x]) _ <LIT 7>]
result 8
Evaluate 3 ... Evaluating <LIT 7>
result 7
Evaluating <LIT 3>
result 3
Evaluating (\x -> [succ _ x])
result (E:<[ succ =succ
]>, V:x, T:[succ _ x]:)
Evaluating [(\x -> [succ _ x]) _ <LIT 8>]
result 9
Evaluating (x -> (y -> [succ _ x]))
result (E:<[ succ =succ
]>, V:x, T:(y -> [succ _ x]):)
Evaluating [(\x -> [succ _ x]) _ <LIT 7>]
result 8
At any rate, there are just two source files, so I didn't
put together a Makefile or anything. They're here:
http://got.net/~landauer/cs/ohdr.ml
http://got.net/~landauer/cs/Danvy_SEC_M.ml
Though the current result is of somewhat questionable utility,
I found it to be worth my time, since I did learn:
- more OCaml;
- how much FP-style pattern matching helps code conciseness; and
- how much extra but necessary infrastructure stuff can be
glossed over (i.e., omitted) in a technical paper like Danvy's.
11:55:33 PM