NOT

Logical negation operator. Inverts a boolean value.

Syntax

NOT expression

Truth Table

A NOT A
TRUE FALSE
FALSE TRUE

Examples

Example file:

-- NOT keyword examples

-- Basic NOT Operations

#EVAL NOT TRUE
#EVAL NOT FALSE

-- Double Negation

#EVAL NOT NOT TRUE
#EVAL NOT NOT FALSE

-- In Conditional Logic

ASSUME hasCriminalRecord IS A BOOLEAN

DECIDE isClean IS NOT hasCriminalRecord

#CHECK isClean

-- With AND

ASSUME personAge IS A NUMBER
ASSUME isBlocked IS A BOOLEAN

DECIDE canAccess IS personAge >= 18 AND NOT isBlocked

#CHECK canAccess

-- With OR

GIVEN isAdmin IS A BOOLEAN, isRestricted IS A BOOLEAN
hasAccess isAdmin isRestricted MEANS isAdmin OR NOT isRestricted

#EVAL hasAccess FALSE FALSE
#EVAL hasAccess FALSE TRUE

-- Negating Compound Expressions

GIVEN a IS A BOOLEAN, b IS A BOOLEAN

-- NOT binds tighter than AND
notAThenB a b MEANS NOT a AND b

-- Use parentheses to negate compound expression
notBoth a b MEANS NOT (a AND b)

#EVAL notAThenB TRUE TRUE
#EVAL notAThenB FALSE TRUE
#EVAL notBoth TRUE TRUE
#EVAL notBoth FALSE TRUE

-- NOT with Comparisons

GIVEN n IS A NUMBER
isNotZero n MEANS NOT (n EQUALS 0)
isNotPositive n MEANS NOT (n > 0)

#EVAL isNotZero 5
#EVAL isNotZero 0
#EVAL isNotPositive 5
#EVAL isNotPositive (-3)

-- In IF Expressions

GIVEN flag IS A BOOLEAN
invertedMessage flag MEANS
  IF NOT flag
  THEN "flag is off"
  ELSE "flag is on"

#EVAL invertedMessage TRUE
#EVAL invertedMessage FALSE
  • AND - Logical conjunction
  • OR - Logical disjunction
  • IMPLIES - Logical implication

See Also