Last active
August 29, 2015 13:57
-
-
Save gatlin/9421778 to your computer and use it in GitHub Desktop.
Languages don't need built-in conditionals! Bah!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define True (λ () (λ (a b) (a)))) | |
(define False (λ () (λ (a b) (b)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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