Created
October 13, 2021 06:24
-
-
Save qnkhuat/e56d35b6e081483525fe05e0925662ef to your computer and use it in GitHub Desktop.
This is all you need for an interpreter
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
; From https://www.youtube.com/watch?v=OyfBQmvr2Hc | |
(define eval-expr | |
(lambda (expr env) | |
(pmatch expr | |
[,x (guard (symbol? x)) | |
(env x)] | |
[(lambda (,x) ,body) | |
(lambda arg) | |
(eval-expr body (lambda (y) | |
(if (eq? x y) | |
arg | |
(env y)))))] | |
[(,rator ,rand) | |
((eval-expr rator env) | |
(eval-expr rand env))])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment