Skip to content

An interpreter for a Scheme dialect with a lazily-generated infinite stack of interpreters interpreting interpreters. The user's program, which is at the top of the stack, can modify any of the interpreters in the infinite stack at any time.

Notifications You must be signed in to change notification settings

StephenBarnes/Demiurge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Demiurge

This is a Python program implementing a dialect of Scheme with a reflective tower, which I built for Stanford's CS242 (Programming Languages).

In "reflective tower", the "tower" is a lazily-generated infinite stack of interpreters interpreting interpreters, with the user's program at the very top. The tower is "reflective" in the sense that any level can modify any lower level.

For example, a program (+ 1 2) will produce output 3; this is ordinary Scheme. Demiurge also allows us to write reflective programs such as (joots (set eval_literal (lambda args "Malkovich"))). The joots stands for "jump out of the system" (coined by Hofstadter) and allows us to modify the interpreter; this example overwrites the interpreter's eval_literal function so that all literals evaluate to the string "Malkovich". If we now run (+ 1 2) we will get the string "MalkovichMalkovich" as our output.

The system allows for arbitrary modifications of the interpreter, so we could for instance write a program which changes our interpreter into a Python interpreter, then write the rest of our program in Python. Or we could modify our interpreter's interpreter to interpret Python, then modify our interpreter to be a Bash interpreter written in Python, then put a Bash program on the top level. As far as I know, there are no practical applications of this, but it's fun.

For an overview of the system, the presentation I gave might be helpful. For implementation details, see the final report, or read the source. For examples of programs, see src/examples.

About

An interpreter for a Scheme dialect with a lazily-generated infinite stack of interpreters interpreting interpreters. The user's program, which is at the top of the stack, can modify any of the interpreters in the infinite stack at any time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published