-
-
Save rightfold/880d4b8a13d49b06c00c to your computer and use it in GitHub Desktop.
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
if <- { |condition, then, else| | |
__nokBuiltinIf condition then else | |
} | |
test { | |
a <- false | |
if false { a := true } | |
assert: ! a | |
if true { a := true } | |
assert: a | |
} | |
unless <- { |condition, args...| | |
if (! condition) args... | |
} | |
test { | |
a <- false | |
unless true { a := true } | |
assert: ! a | |
unless false { a := true } | |
assert: a | |
} | |
repeat <- { |n, body| | |
while {> n 0} { | |
body! | |
n := - n 1 | |
} | |
} | |
test { | |
n <- 0 | |
repeat 10 { n := n + 1 } | |
assert: = n 10 | |
} | |
switch <- { |topic, clauses...| | |
for (pairNeighbors clauses) { |clause| | |
if (= topic (nth clause 0)!) { | |
(nth clause 1)! | |
break! | |
} | |
} | |
} | |
test { | |
n <- 0 | |
switch 2 | |
| {1} { n := 1 } | |
| {2} { n := 2 } | |
| {3} { n := 3 } | |
assert: = n 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment