Created
March 1, 2019 12:47
-
-
Save milesrout/f14eaf7ffeb37a70fca9ffc9cd233382 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
# normal macro | |
# \ is ` and $ is , | |
macro assert(e): | |
\(if DEBUG: | |
if not $e: | |
raise AssertionError($(stringify(e))) | |
# control structure macro | |
macro unless(arms): | |
assert(len(arms) in {1, 2}) | |
if len(arms) == 1: | |
[cond], body = arms[0] | |
return \(if not $cond: | |
$@body) | |
else: | |
[cond], body = arms[0] | |
[], alt = arms[1] | |
return \(if not $cond: | |
$@body | |
else: | |
$@alt) | |
control_structure (unless <test>) (else) | |
x = 1 | |
unless x == 0: | |
print('x is not equal to zero') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment