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 67 of 116nils-m-holm7 years ago#Unification of the terms X and Y in the environment E in LISP (part of a PROLOG interpreter): (defun unify (x y e) (let ((x (look-up x e)) (y (look-up y e))) (cond ((eq x y) e) ((variable-p x) (cons (list x y) e)) ((variable-p y) (cons (list y x) e)) ((or (atom x) (atom y)) nil) (#t (let ((ne (unify (car x) (car y) e))) (and ne (unify (cdr x) (cdr y) ne))))))) LOOK-UP looks up X or Y in E, VARIABLE-P returns truth, if X or Y is a variable.
Ask HN: What is the most beautiful piece of code you've ever read?476 pointsby seisvelas (on Hacker News)7 years ago
nils-m-holm7 years ago#Unification of the terms X and Y in the environment E in LISP (part of a PROLOG interpreter): (defun unify (x y e) (let ((x (look-up x e)) (y (look-up y e))) (cond ((eq x y) e) ((variable-p x) (cons (list x y) e)) ((variable-p y) (cons (list y x) e)) ((or (atom x) (atom y)) nil) (#t (let ((ne (unify (car x) (car y) e))) (and ne (unify (cdr x) (cdr y) ne))))))) LOOK-UP looks up X or Y in E, VARIABLE-P returns truth, if X or Y is a variable.
Comments (380) 116 threads
Show all comments
Showing thread 67 of 116