Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:19
Show Gist options
  • Save rightfold/880d4b8a13d49b06c00c to your computer and use it in GitHub Desktop.
Save rightfold/880d4b8a13d49b06c00c to your computer and use it in GitHub Desktop.
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