Back to front pageView on Hacker News (opens in a new tab)Ask HN: What is the most beautiful piece of code you've ever read?476 pointsby seisvelas (on Hacker News)7 years agoPreferably an elegant snippet rather than an entire (well engineered) codebase.Comments (380) 116 threadsShow all commentsShowing thread 7 of 116[-]labria7 years ago4 replies# (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=OyfBQmvr2Hcchombier7 years ago#Once you've seen this one, it's difficult not to rank it first :)[-]estomagordo7 years ago1 reply#Great. In 90 minutes I may be able to know what you're talking about.[-]estomagordo7 years ago1 reply#Is it a complete lisp interpreter, written in lisp?Globz7 years ago#Yes, it uses pmatch behind the scene to match your expr against the evaluator.https://github.com/webyrd/quines/blob/master/pmatch.scmI have to agree, this like rank #1 in my book!lioeters7 years ago#This 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 softwarehttp://www.michaelnielsen.org/ddi/lisp-as-the-maxwells-equat...quickthrower27 years ago#Y Combinator?
Ask HN: What is the most beautiful piece of code you've ever read?476 pointsby seisvelas (on Hacker News)7 years ago
labria7 years ago4 replies# (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
Globz7 years ago#Yes, it uses pmatch behind the scene to match your expr against the evaluator.https://github.com/webyrd/quines/blob/master/pmatch.scmI have to agree, this like rank #1 in my book!
lioeters7 years ago#This 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 softwarehttp://www.michaelnielsen.org/ddi/lisp-as-the-maxwells-equat...
Comments (380) 116 threads
Show all comments
Showing thread 7 of 116
https://github.com/webyrd/quines/blob/master/pmatch.scm
I have to agree, this like rank #1 in my book!
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-equat...