Created
May 2, 2015 03:43
-
-
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/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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