2 days ago · Tech · 0 comments

To some extent, Lisp just extends and thus includes lambda calculus. Indeed, short functions already permit: |(+ $ 1) # λx.x+1 (|(+ $ 1) 3) # (λx.x+1) 3 (|(+ $ 1) (|(+ $ 2) 3)) # (λx.x+1) ((λy.y+2) 3) Going a bit further, a simple macro gives us more or less everything: (defmacro λ `Executable lambda calc: ((λ x . + 5 x) 5)` [v dot & args] (if (= 1 (length args)) ~(fn [,v] ,(first args)) # to handle e.g. identity: ((λ x . x) 5) ~(fn [,v] (,;args)))) ((λ x . + 1 x) 3) # (λx.x+1) 3 ((λ x . + x 1) ((λ y . + y 2) 3)) # (λx.x+1) ((λy.y+2) 3) # n.b. these versions are the same: (def K (λ x . (λ y . x))) (def K (λ x . λ y . x)) On the basis of this macro, you can implement anything you want: (def TRUE (λ x . λ y . x)) (def FALSE (λ x . λ y . y)) (def IF (λ p . λ a . λ b . (p a) b)) # evaluates both branches (def AND (λ p . λ q . (p q) p)) (def OR (λ p . λ q . (p p) q)) (def NOT (λ p . λ a . λ b . (p b) a)) (def ZERO (λ f . λ x . x)) (def SUCC (λ n . λ f . λ x . f ((n f) x))) (def ONE (SUCC…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.