Skip to content

Instantly share code, notes, and snippets.

@milesrout
Created March 1, 2019 12:47
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 milesrout/f14eaf7ffeb37a70fca9ffc9cd233382 to your computer and use it in GitHub Desktop.
Save milesrout/f14eaf7ffeb37a70fca9ffc9cd233382 to your computer and use it in GitHub Desktop.
# 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