Skip to content

Instantly share code, notes, and snippets.

@gatlin
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatlin/9421778 to your computer and use it in GitHub Desktop.
Save gatlin/9421778 to your computer and use it in GitHub Desktop.
Languages don't need built-in conditionals! Bah!
(define True (λ () (λ (a b) (a))))
(define False (λ () (λ (a b) (b))))
(define-syntax-rule (displayln str)
(display (format
(string-append str "~n"))))
(define (show-bool b)
(b (λ () (displayln "True"))
(λ () (displayln "False"))))
(show-bool (True))
; "True"
(show-bool (False))
; "False"
(define-syntax-rule (if/g condition then else)
(let ((then-f (λ () then))
(else-f (λ () else)))
(condition then-f else-f)))
(if/g (True)
(displayln "Condition was true")
(displayln "Condition was false"))
; "Condition was true"
(if/g (False)
(displayln "Condition was true")
(displayln "Condition was false"))
; "Condition was false
(define (and/g p q)
(p
(q (λ () True)
(λ () False))
(q (λ () False)
(λ () False))))
(define (or/g p q)
(p
(q (λ () True)
(λ () True))
(q (λ () True)
(λ () False))))
(define (not/g b)
(b False
True))
(define (and/s p q)
(p (λ() q)
(λ() p)))
(define (or/s p q)
(p (λ () p)
(λ () q)))
(define (not/s b)
(b False
True))
(show-bool (and/s (True) (False)))
(show-bool (and/s (False) (True)))
(show-bool (and/s (True) (True)))
(show-bool (or/s (False) (True)))
(show-bool (or/s (True) (False)))
(show-bool (or/s (False) (False)))
(show-bool (not/s (and/s (False) (True))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment