• On porting Scheme to Common Lisp

    Sun, 09 Mar 2008 21:19:54 +0100

    Lately, I have been porting a Scheme interpreter from Scheme to Common Lisp. This interpreter features some quite heavy transformations based on non-hygienic macros. Being not a Common Lisp programmer, I realised that porting that code was non as trivial as I expected (and that naming conventions in CL are sometimes a bit weird, unlike Scheme whose various reports state that all predicates end with the character "?"). Beside the easy code rewrites like DEFINE in DEFVAR or DEFUN, and a few brackets moved from here to there, I happen to be forced to quote some symbols in my macros, which surprised me quite a bit. After all those code transforms were done, I was left with a sneaky bug. Some macro-generated function would not have a value, according to what clisp was saying (and sbcl's errors didn't help me at all). I spent a couple of days checking my code again and again, looking for some kind of symbol which I would have forgotten to quote. And tonight, I found the answer.


    After reducing my code to the smallest possible (that is, removing all the interpreter, most of macros, to have just the buggy part, which still was 180 LoC), I came to find out that, in fact, while porting my code, I had changed a CADDR into a CADR, which tried to access the generated closure name as an array. Common Lisp being a Lisp2, the error was indeed meaningful!


    I wonder what will happen when I try to port my program to Arc. (But do I really want that?)