Created
February 23, 2018 19:33
-
-
Save vbuaraujo/5d177986e4b031e48e96ffbeb8fb4464 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 switch | |
(syntax-rules (default) | |
[(switch expr clauses ...) | |
(let ([result expr]) | |
(%handle-switch-clauses result clauses ...))])) | |
(define-syntax %handle-switch-clauses | |
(syntax-rules (default) | |
[(_ result) 'Nada™] | |
[(_ result (default forms ...)) (begin forms ...)] | |
[(_ result (value forms ...) other-clauses ...) | |
(if (equal? result value) | |
(begin forms ...) | |
(%handle-switch-clauses result other-clauses ...))])) | |
(define n 1) | |
(switch n | |
[1 (display "foo\n")] | |
[2 (display "bar\n")] | |
[default (display "other\n")]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment