Lithp.py (~2008) Lithp.py, a Lisp interpreter for John McCarthy's original Lisp, was released around 2008 by developer Fogus. The interpreter, written in Python 2.6.1+, includes core functions like car, cdr, cons, and lambda, and provides a REPL environment. It is available at fogus.me/fun/lithp/. lithp.py | | |---|---| | Lithp - A interpreter for John McCarthy's original Lisp. The heavily documented code for It wasn't enough to write the Lisp interpreter -- I also wanted to share what I learned with The Lithp interpreter requires Python 2.6.1+ to function. please add comments, report errors, annecdotes, etc. to the | python import pdb import getopt, sys, io from env import Environment from fun import Function from atom import TRUE from atom import FALSE from lisp import Lisp from reader import Reader from error import Error from fun import Lambda from fun import Closure NAME = "Lithp" VERSION = "v1.1" WWW = "http://fogus.me/fun/lithp/" PROMPT = "lithp" DEPTH MARK = "." | | The Lithper class is the interpreter driver. It does the following: | class Lithp Lisp : | | python def init self : iostreams= sys.stdin, sys.stdout, sys.stderr self.stdin, self.stdout, self.stderr = iostreams self.debug = False self.verbose = True self.core = True self.closures = True self.rdr = Reader self.environment = Environment self.init | | python def init self : | | | Define core functions | self.environment.set "eq", Function self.eq self.environment.set "quote", Function self.quote self.environment.set "car", Function self.car self.environment.set "cdr", Function self.cdr self.environment.set "cons", Function self.cons self.environment.set "atom", Function self.atom self.environment.set "cond", Function self.cond | | Define utility function | self.environment.set "print", Function self.println | | Special forms | self.environment.set "lambda", Function self.lambda self.environment.set "label", Function self.label | | Define core symbols | self.environment.set "t", TRUE | | There is one empty list, and it's named | self.environment.set "nil", FALSE | | Define meta-elements | self.environment.set " lithp ", self self.environment.set " global ", self.environment | | python def usage self : self.print banner print print NAME.lower , "