Boolean
Logic
a && b → in?: [True, False] | a is-a?: Boolean | b is-a?: Boolean
Test whether a
and b
are both True
. This is actually a macro which calls the short-circuiting and:
.
a || b → in?: [True, False] | a is-a?: Boolean | b is-a?: Boolean
Test if either a
or b
are True
. This is actually a macro which calls the short-circuiting or:
.
a and: b → in?: [True, False] | a is-a?: Boolean | b is-a?: Block
A short-circuiting form of &&
, only call
ing the right-hand side if a
is True
.
Control Flow
if: test then: yes else: no → any | test is-a?: Boolean | yes is-a?: Block | no is-a?: Block
Basic if-then-else control flow. If test
is True
, yes
is call
ed, otherwise no
is. The result is the result of whichever block is called.
Example:
> if: (1 == 0) then: { "Uh-oh." } else: { "We're good!" } "We're good!"
when: test do: action → @ok | test is-a?: Boolean | action is-a?: Block
Sends call
to action in-context
if test
is True
, always returning @ok
.
while: test do: action → @ok | test is-a?: Block | action is-a?: Block
Continually sends call
to action in-context
until test
yields False
.
condition: branches → any | branches is-a?: Block
Similar to Scheme's cond
, this construct takes a block pairing tests with their branch, and goes through each pairing until a test yields True
, in which case it evaluates the expression that test was associated with.
If no branches yield True
, @no-true-branches
is raised.
NOTE: This is a macro which expands to chained if:then:else:
dispatches.
Example:
> condition: { False -> "Hello!" print; True -> "Goodbye!" print } Goodbye! "Goodbye!" > condition: { 1 == 1 -> 0; otherwise -> 1 } 0
otherwise → True
Alias for True
for use in condition:
, or anywhere else where it would look nicer.