Skip to content
Abe Pralle edited this page Sep 7, 2022 · 7 revisions

Syntax

contingent
  # any mix of statements along with:
  necessary (x)  # jump to 'unsatisfied' if x is false
  sufficient (y) # jump to 'satisfied' if y is true
  if (...) escapeContingent
  # fall through to 'satisfied'
satisfied
  # statements
unsatisfied
  # statements
endContingent

Example

# Print prime numbers between 1 and 100
forEach (n in 1..100)
  contingent
    # Only numbers 2+ can be prime
    necessary  (n > 1)

    # 2 is a prime number
    sufficient (n == 2)

    # Any other even number is not prime
    necessary  (n & 1 == 1)

    # Mod the number with odd numbers 3..sqrt(n).
    forEach (divisor in 3..Math.sqrt(n) step 2)
      # Remainders must be non-zero
      necessary (n % divisor)?
    endForEach

  satisfied
    println n + " is prime"

  endContingent
endForEach
Clone this wiki locally