atomo-0.4: prelude/comparable.atomo
a matches?: b := a == b
a <=> b :=
condition: {
a > b -> 1
a < b -> -1
otherwise -> 0
}
x max: y :=
if: (x > y) then: { x } else: { y }
x min: y :=
if: (x < y) then: { x } else: { y }
for-macro regexp?: e :=
e type match: {
@primitive ->
(evaluate: e) is-a?: Regexp
@macro-quote ->
e name == "r"
_ -> False
}
macro (x case-of: (bs: Block))
{ chain = bs contents reduce-right:
{ `(~test -> ~branch) x |
condition: {
regexp?: test ->
`((~test match: !v) match: {
@none -> ~x
@(ok: !b) -> !b bindings join: { ~branch }
})
test == '_ -> branch
otherwise ->
`(if: (~test matches?: !v) then: { ~branch } else: { ~x })
}
} with: '@ok
`({ !v | ~chain } call: ~x)
} call