8 March 2006
PScheme
It’s a big day in the development of PScheme. As of 5:07 PM on March 07 2006, tail recursion was properly implemented. It wasn’t until 5:40 that closures were handled correctly, which meant the arglist in tailrec procedures had to be conventionally backwards, but now that works too.
So the todo list still has some big things on it:
- Macros: I implemented let as a function, but really, let, let*, letrec and cond should be macros, not functions. I’m not about to make a letrec function, so macros need addressing soon.
- Error Catching: The interpretter is pretty resilent. It’s got syntax validation with meaningful errors, meaningful compiler errors, but not much in the runtime arena. The most notable error I run into deals with conventional recursion. PHP’s stack allows only 2000 nested function calls. With tail-recursion,
(fact 1 1)and(fact 2000 1)take the same amount of space on the stack. With normal recursion,(fact 1)takes about as much space as the tail-recursive variety, and(fact 1500)is just about the largest factorial that can be computed.(fact 1600does break everything. I’m not certain it’s the function-call limit, because I get pretty close to 20MB of memory usage just as it crashes. For all I know, 20MB is another limit in PHP. So I need some more tracking data inserted in there so I can abort as 2000-calls approaches. 20MB is a whole nother beast on Windows, because memory_get_usage() doesn’t exist. - Procedural and OOP programming: I’ve got none of the implicit begins or even a begin statement yet.
- Datatypes: Complex numbers, especially, aren’t handled at all. They’re recognized while parsing, but at runtime, they’re treated as numbers. That tends not to work out so well.
But the most important stuff is done. Tail recursion took about a month and almost made me abandon PHP for this project. But with enough loops and checks for tail-context, it was fake-able.
PScheme on the website will be updated this weekend, if I ever get an internet connection at home again.

