Top

Noc has control flow thanks to the pattern matching with the case combinator. With control flow we can have a particular order for the expressions and the pattern matching allows to match to some patterns like ["john"] or [_]:

"john"
[
    [["john"] ["you are john!"]]
    [[_] ["you are not john!"]]
] case print


"you are john!"

The [_] pattern run the default action (otherwise), it matches any pattern.

Example: (if combinator)

Source: std/bool.noc
def if = {
  [
    [[True] [swap pop unquote]]
    [[False] [pop unquote]]
  ] case
}


load std:bool

def main = {
    ["else" print] ["then" print] True if
}