Comparison Keywords

Comparison keywords are used to compare values and return BOOLEAN results. Most have both textual (keyword) and symbolic forms.

Keywords

Keyword Symbol Meaning
EQUALS = Equality
GREATER THAN > Greater than
LESS THAN < Less than
AT LEAST >= Greater or equal
AT MOST <= Less or equal
ABOVE > Synonym for GREATER THAN
BELOW < Synonym for LESS THAN

Equality: EQUALS

Tests if two values are equal.

Syntax

value1 EQUALS value2
value1 = value2

Examples

Example file:

-- Comparison keyword examples

-- EQUALS

-- Numeric equality
#EVAL 5 EQUALS 5
#EVAL 5 = 5

-- String equality
#EVAL "hello" EQUALS "hello"
#EVAL "hello" = "world"

-- Boolean equality
#EVAL TRUE EQUALS TRUE
#EVAL FALSE = FALSE

-- GREATER THAN / ABOVE

-- Numeric greater than
#EVAL 10 GREATER THAN 5
#EVAL 10 > 5
#EVAL 10 ABOVE 5

-- String comparison (lexicographic)
#EVAL "b" GREATER THAN "a"
#EVAL "zebra" > "apple"

-- LESS THAN / BELOW

-- Numeric less than
#EVAL 3 LESS THAN 7
#EVAL 3 < 7
#EVAL 3 BELOW 7

-- AT LEAST (>=)

#EVAL 5 AT LEAST 5
#EVAL 6 AT LEAST 5
#EVAL 4 AT LEAST 5

#EVAL 5 >= 5
#EVAL 6 >= 5

-- AT MOST (<=)

#EVAL 4 AT MOST 10
#EVAL 10 AT MOST 10
#EVAL 11 AT MOST 10

#EVAL 4 <= 10
#EVAL 10 <= 10

-- Combined Comparisons

ASSUME age IS A NUMBER

DECIDE isWorkingAge IS
      age AT LEAST 18
  AND age AT MOST 65

#CHECK isWorkingAge

-- Comparison in Functions

GIVEN n IS A NUMBER
GIVETH A STRING
classifyNumber n MEANS
  IF n LESS THAN 0
    THEN "negative"
    ELSE IF n EQUALS 0
           THEN "zero"
           ELSE "positive"

#EVAL classifyNumber (-5)
#EVAL classifyNumber 0
#EVAL classifyNumber 42

-- Range Check Pattern

GIVEN val IS A NUMBER
      minVal IS A NUMBER
      maxVal IS A NUMBER
GIVETH A BOOLEAN
inRange val minVal maxVal MEANS
  val AT LEAST minVal AND val AT MOST maxVal

#EVAL inRange 5 1 10
#EVAL inRange 15 1 10
#EVAL inRange 1 1 10
#EVAL 5 EQUALS 5           -- TRUE
#EVAL "hello" = "hello"    -- TRUE
#EVAL 5 EQUALS 3           -- FALSE

Ordering: GREATER THAN, LESS THAN

Compare ordered values (numbers, strings, dates).

Syntax

value1 GREATER THAN value2
value1 > value2

value1 LESS THAN value2
value1 < value2

Examples

#EVAL 10 GREATER THAN 5    -- TRUE
#EVAL 10 > 5               -- TRUE

#EVAL 3 LESS THAN 7        -- TRUE
#EVAL 3 < 7                -- TRUE

Inclusive: AT LEAST, AT MOST

Compare with inclusive bounds.

Syntax

value1 AT LEAST value2     -- value1 >= value2
value1 >= value2

value1 AT MOST value2      -- value1 <= value2
value1 <= value2

Examples

#EVAL 5 AT LEAST 5         -- TRUE (equal counts)
#EVAL 5 >= 5               -- TRUE

#EVAL 4 AT MOST 10         -- TRUE
#EVAL 4 <= 10              -- TRUE

Synonyms: ABOVE, BELOW

Alternative keywords for greater/less than.

#EVAL 10 ABOVE 5           -- TRUE (same as GREATER THAN)
#EVAL 3 BELOW 7            -- TRUE (same as LESS THAN)

Combining Comparisons

Comparisons return BOOLEAN values and can be combined with logical operators.

ASSUME age IS A NUMBER
ASSUME income IS A NUMBER

-- Combined conditions
DECIDE isEligible IS
      age AT LEAST 18
  AND age AT MOST 65
  AND income GREATER THAN 30000

Type Compatibility

Comparisons work on:

  • NUMBER - Numeric comparison
  • STRING - Lexicographic comparison
  • DATE - Chronological comparison
  • BOOLEAN - FALSE < TRUE
  • Custom types - If ordered
  • AND - Combine comparisons
  • OR - Alternative conditions
  • IF - Use comparisons in conditionals

See Also