Skip to content

Instantly share code, notes, and snippets.

@clementi
Created May 2, 2015 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clementi/0edded501ff304d34609 to your computer and use it in GitHub Desktop.
Save clementi/0edded501ff304d34609 to your computer and use it in GitHub Desktop.
Simple Interpreter for the Lambda Calculus (from http://matt.might.net/articles/implementing-a-programming-language/)
#lang racket
(require racket/match)
(define (eval exp env)
(match exp
[`(,f ,e) (apply (eval f env) (eval e env))]
[`(λ ,v . ,e) `(closure ,exp ,env)]
[(? symbol?) (cadr (assq exp env))]))
(define (apply f x)
(match f
[`(closure (λ ,v . ,body) ,env)
(eval body (cons `(,v ,x) env))]))
(display (eval (read) '()))
(newline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment