Created
May 22, 2022 21:20
-
-
Save felix-lipski/f3d3bac935ec6f8f9c3e65340e51a6a7 to your computer and use it in GitHub Desktop.
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
(load "pmatch.scm") | |
(define eval-expr | |
(lambda (expr env) | |
(pmatch expr | |
[,n (guard (number? n)) n] | |
[,x (guard (symbol? x)) | |
(env x)] | |
[(lambda (,x) ,body) | |
(lambda (arg) | |
(eval-expr | |
body | |
(lambda (var) | |
(if (eq? x var) | |
arg | |
(env var)) | |
)))] | |
[(,rator ,rand) | |
((eval-expr rator env) | |
(eval-expr rand env))]))) | |
(define evalo | |
(lambda (expr) | |
(eval-expr | |
expr | |
(lambda | |
(var) | |
(error 'lookup "unbound"))))) | |
;; taken from "The Most Beautiful Program Ever Written" by William Byrd, presented at PWL NYC | |
;; https://youtu.be/OyfBQmvr2Hc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment