7 ms·
(define eval-expr (lambda (expr env) (pmatch expr [`,x (guard (symbol? x)) (env x)] [`(lambda (,x) ,body) (lambda
by labria 7y ago
(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))])))
There's an amazing talk about it: https://www.youtube.com/watch?v=OyfBQmvr2Hc https://www.youtube.com/watch?v=OyfBQmvr2Hc
- chombier 7y agoOnce you've seen this one, it's difficult not to rank it first :)
- estomagordo 7y agoGreat. In 90 minutes I may be able to know what you're talking about.
- estomagordo 7y agoIs it a complete lisp interpreter, written in lisp?
- deleted 7y ago[deleted]
- Globz 7y agoYes, it uses pmatch behind the scene to match your expr against the evaluator. https://github.com/webyrd/quines/blob/master/pmatch.scm https://github.com/webyrd/quines/blob/master/pmatch.scm I have to agree, this like rank #1 in my book!
- lioeters 7y agoThis is exactly what came to mind when seeing the question. I was just recently (re-)reading an article that goes in depth: Lisp as the Maxwell’s equations of software http://www.michaelnielsen.org/ddi/lisp-as-the-maxwells-equations-of-software/ http://www.michaelnielsen.org/ddi/lisp-as-the-maxwells-equat...
- quickthrower2 7y agoY Combinator?