Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Thanks! Any suggestions for resources to help me get started? I'm not afraid of complicated terminology as long as there is a way for me to easily figure out what it means (whether Wikipedia, a glossary, or simply a great example).


Start with untyped lambda calculus, augmented with numbers, and addition. That's what I did. Such a language is dead simple: you only have four kinds of expressions: numbers, additions, functions, and function calls.

Write a parser and a printer (a pretty printer would be best, but you don't have to). Use one to test the other. Then write an interpreter, who takes an expression as input, evaluates it, and spits out a number.

The whole thing should fit in a couple hundred lines, tops. The only real difficulty is to evaluate function calls. The rest is only a matter of catching runtime errors (like trying to add a number and a function). To properly implement your language, you may have to learn about closures and lexical scoping, though there are tricks to sidestep the issue.

To test your language, check out the Y and Z combinators here https://en.wikipedia.org/wiki/Fixed_point_combinator and use the Z combinator to implement the factorial function.

The next step is to flesh out your language a bit. I suggest you augment it with "let" bindings first: it's just syntax sugar over lambdas: you change your parser, but you don't have to touch the interpreter.


In addition to the article here and "Write Yourself a Scheme in 48 Hours" (the implementation language is Haskell, which may be a barrier)[1], and some others mentioned in the comments here, there's Peter Norvig's "(How to Write a (Lisp) Interpreter (in Python))"[2] and "(An ((Even Better) Lisp) Interpreter (in Python))"[3].

Every last Lisp book out has at least one implementation of a Lisp evaluator, although most don't go into all of the other stuff you have to do like parsing. On the other hand, there are a lot of books and articles that focus on parsing as if it were the most important part.

Someone has already mentioned Structure and Interpretation of Computer Programs[4], additionally, there is the Essentials of Programming Languages[5], Paul Wilson's An Introduction to Scheme and its Implementation[6], and some things I haven't read, like Simon Peyton Jones and David Lester's Implementing functional languages: a tutorial[7].

[1] http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_H...

[2] http://norvig.com/lispy.html

[3] http://norvig.com/lispy2.html

[4] http://mitpress.mit.edu/sicp/full-text/book/book.html

[5] http://www.eopl3.com/

[6] ftp://ftp.cs.utexas.edu/pub/garbage/cs345/schintro-v14/schintro_toc.html

[7] http://research.microsoft.com/en-us/um/people/simonpj/Papers...




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: