Skip to content
Tech News
← Back to articles

Lithp.py (~2008)

read original more articles
Why This Matters

Lithp.py exemplifies early efforts to build a Lisp interpreter in Python, highlighting the foundational work involved in creating programmable shells and scripting languages. Its design reflects the importance of understanding core language constructs and environment management, which continue to influence modern language development and embedded scripting solutions.

Key Takeaways

# The Lithper class is the interpreter driver. It does the following: class Lithp ( Lisp ):

# Initialize the global environment Parse the cl arguments and act on them as appropriate Initialize the base Lisp functions Read input Evaluate Print Loop back to #4 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 ()

# 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 nil self . environment . set ( "nil" , FALSE )

# Define meta-elements self . environment . set ( "__lithp__" , self ) self . environment . set ( "__global__" , self . environment )

# def usage ( self ): self . print_banner () print print NAME . lower (), " <options> [lithp files]

... continue reading