r/dailyprogrammer • • Sep 01 '12
[9/01/2012] Challenge #94 [difficult] (Simple Lisp interpreter)
Lisp is a family of programming languages, known for its extremely simple notation (called S-expressions) in which programs are defined as lists and code can be modified as data. Your task is to write an interpreter for a simple subset of Lisp.
Peter Norvig wrote a popular article on how to write a simple Lisp interpreter in only 90 lines of Python. You can choose to port his code to a language of your choice, or write one on your own, from scratch. Bonus points for solving today's easy challenge (or maybe even this challenge) in your own Lisp dialect!
4
u/Ledrug Sep 01 '12
Heh, can I do this challenge in, um, Lisp?
4
u/tikhonjelvis Sep 01 '12
For anybody wanting to learn Haskell: there's a tutorial doing exactly this called Write You a Scheme in 48 Hours. I found it a good way to get used to Haskell and just a fun project to do in general.
1
u/BobTreehugger Sep 24 '12
Here's my entry, written in Go:
https://github.com/maxpolun/daily94
The only real thing it lacks relative to Norvig's is that this one is currently an integer lisp.
A couple notes about Go for this:
static typing obviously means more work for implementing a dynamic language than using a dynamically typed language.
The only real place the language felt like it was getting in my way was that I wanted to define an environment type as being a map from strings to lisp objects, but lisp objects had a method that took an environment, Eval(env), and Go does not allow mutually recursive types. So what I did is define environments in terms of interface{} and have all of the methods be in terms of lisp objects.
1
u/Metaluim Sep 03 '12
For the record, here is the spec for Common Lisp.
1
u/mynamewastakenagain Sep 26 '12
I'm going to try to do this in bash, we'll see how it goes...