Values and types Isis software documentation

# Values and types

This document explains the value and type operators in Isis, including routines for comparing values, checking types, and casting values to different types.

### Logical operators

The Isis core syntax provides the logical operators and, or, nand, and nor:
( and exp exp ... )
( or exp exp ... )
( nand exp exp ... )
( nor exp exp ... )
The and statement returns True only if all its expressions evaluate to logically true values. The or statement returns True if just one or more of its expressions evaluate to logically true values. Otherwise, these expressions return False. nand and nor are analogous to and and or except they will return the opposite value ("not" and and "not" or).

Isis considers a value to be logically true if it is a non-zero number, character, or address, or if the value is a procedure or a non-empty list, or if it is the boolean True. Any other value, including Null, is considered logically false.

In these constructs, Isis only evaluates the necessary expressions from left to right to determine the result. For example, if the first expression in an and statement evaluates to a false value, any remaining expressions are not evaluated, because their values would have no effect on the final result.

### Logical not operator

(not val) # invert logical value of val This operator inverts a value's logical value, and returns either True or False. See above for information on what kinds of values are considered logically true or logically false.
-> (not False) True -> (not 10.1) False -> (not 0) True

### Equality operators

(= val val ...) # return True if vals are equal (!= val val ...) # return True if vals are not equal (eq? val val ...) # same as = (equal) (neq? val val ...) # same as != (not equal) These operators are used for comparing two or more values. For eq? or =, the result is True if all the values are identical, and False otherwise. neq? and != return the opposite result (effectively the same as (not (eq? ...)) ). Any type of Isis value is allowed, including lists, in which case corresponding elements are compared.

Note that the types of the arguments must match in order to be considered equal (i.e. the integer 3 is not equal to the real number 3.0). If necessary, you can use the type casting operators explained below to convert arguments to the same type.

-> (set x [2 3]) [ 2 3 ] -> (set y [2 3]) [ 2 3 ] -> (set z [4 5]) [ 4 5 ] -> (!= x y) False -> (= x y) True -> (= x y z) False

### Inequality operators

(< val1 val2) # return True if val1 < val2 (> val1 val2) # return True if val1 > val2 (<= val1 val2) # return True if val1 <= val2 (>= val1 val2) # return True if val1 >= val2 (lt? val1 val2) # same as < (less than) (gt? val1 val2) # same as > (greater than) (leq? val1 val2) # same as <= (less than or equal to) (geq? val1 val2) # same as >= (greater than or equal to) These operators each expect two arguments, which must be integers or real numbers. The types of the values need not match. The result is True if the condition holds, and False of not, or Null if the values are not of the expected type.
-> (> 2 4) False -> (>= 10 10.1) False -> (> [2 3] [4 5]) ** >: 1st arg not a number. Null

### Type queries

(integer? val) # return True if val is an integer (real? val) # return True if val is a real number (boolean? val) # return True if val is a boolean (character? val) # return True if val is a character (address? val) # return True if val is a memory address (procedure? val) # return True if val is a procedure (list? val) # return True if val is a list (integer-list? val) # return True if val is a list of integers (real-list? val) # return True if val is a list of real numbers (boolean-list? val) # return True if val is a list of booleans (character-list? val) # return True if val is a list of characters (string? val) # same as character-list? (address-list? val) # return True if val is a list of memory addresses (procedure-list? val) # return True if val is a list of procedures (list-list? val) # return True if val is a list of lists These procedures check the type of a single argument. The list routines check if the argument is a non-empty list containing only items of the specified type. The result is either True or False.
-> (integer? 3) True -> (integer? 3.0) False -> (procedure? +) True -> (procedure? (proc (x) x)) True -> (list? [2 3 4]) True -> (list? "sparky") True -> (integer-list? [1 2 3]) True -> (integer-list? [1 2 3.3]) False -> (string? "yojimbo") True -> (string? [ 'f' 'i' 's' 'h' ]) True -> (string? "") False -> (real-list? []) False -> (list-list? [ [2 3] [4 5] [6 9] ]) True -> (list-list? [ "time" "bandit" ]) True -> (list-list? [ [] [] [] ]) True -> (list-list? [ 3 2 [ 10 11 ] ]) False

### Type casting

(integer val) # convert val to an integer (real val) # convert val to a real number (boolean val) # convert val to a boolean (character val) # convert val to a character (address val) # convert val to a memory address (procedure val) # convert val to a procedure These primitives accept a single value and cast it to the specified type. Not all casts are valid, in which case an error message will be printed and Null will be returned.
-> (integer 3.5) 3 -> (real -10) -10.000000 -> (character 42) '*' -> (boolean 0) False -> (address 100000) 0x186a0 -> (procedure 81) ** procedure: Invalid cast. Null