packages feed

atomo-0.2: prelude/boolean.atomo

False and: _ = False
True and: (b: Block) := b call

True or: _ = True
False or: (b: Block) := b call

macro a && b := `(~a and: { ~b })
macro a || b := `(~a or: { ~b })

True not := False
False not := True

if: True then: (a: Block) else: Block :=
  a call

if: False then: Block else: (b: Block) :=
  b call

when: False do: Block = @ok
when: True do: (action: Block) :=
  { action in-context call
    @ok
  } call

while: (test: Block) do: (action: Block) :=
  when: test call do:
    { action in-context call
      while: test do: action
    }

True show := "True"
False show := "False"

otherwise := True

macro condition: (bs: Block) :=
  { ps = bs contents map:
      { pair |
        [c, e] = pair targets
        c -> e
      }

    ps reduce-right:
      { pair x |
        `(if: ~(pair from) then: { ~(pair to) } else: { ~x })
      } with: `(raise: @no-true-branches)
  } call