 # compare

#### Overview

The compare function returns 0 if two objects: {obj1} and {obj2} are equivalent. If the value of the first object {obj1} is less than the value of the second object {obj1}, then -1 is returned. If {obj1} is greater than {obj2}, then +1 is returned.

### String

The compare Function returns 0 if both Strings are equivalent. If string1 is less than string2, then -1 is returned. If string1 is greater than string2, then +1 is returned.

### Symbol

The compare Function returns 0 if both Symbols are equivalent. If {sym1} is less than {sym2} , then -1 is returned. If {sym1} is greater than {sym2} , then +1 is returned.

### Structure

The compare Function returns 0 if its arguments are equivalent. If {struct1} is less than {struct2} , then -1 is returned. If {struct1} is greater than {struct2} , then +1 is returned. Two Structures are equal if the keys and values from both are equal.

### Dictionary

The compare Function returns 0 if its arguments are equivalent. If {dict1} is less than {dict2} , then -1 is returned. If {dict1} is greater than {dict2} , then +1 is returned. Two Dictionaries are equal if the keys and values from both are equal.

### Directory

The compare Function returns 0 if its arguments are equivalent. If {dir1} is less than {dir2} , then -1 is returned. If {dir1} is greater than {dir2} , then +1 is returned. Two Directories are equal if the keys and values from both are equal.

### Brick

The compare function returns 0 if its field data elements are identical. If {brick1} is less than {brick2}, then -1 is returned. If {brick1} is greater than {brick2} , then +1 is returned. Two Bricks are equal if their field data elements are identical.

### Matrix

The compare Function returns 0 if both Matrix arguments are equivalent. If Matrix1 is less than Matrix2, then -1 is returned. If Matrix1 is greater than Matrix2, then +1 is returned. Two Matrices are equal if all of the values from both are equal.

### NumMatrix

The compare Function returns 0 if both NumMatrix arguments are equivalent. If NumMatrix1 is less than NumMatrix2, then -1 is returned. If NumMatrix1 is greater than NumMatrix2, then +1 is returned. Two NumMatrices are equal if all of the values from both are equal.

### Pair

The compare function returns 0 if both Pair (or List) arguments are equivalent. If pair1 is less than pair2, then -1 is returned. If pair1 is greater than pair2, then +1 is returned. Two Pairs are equal if all of the values from both are equal.

### Number

The compare function returns 0 if two numbers {num1} and {num2} are equivalent. If {num1} is less than {num2}, then -1 is returned. If {num1} is greater than {num2}, then +1 is returned.

### Date

Comparison of Date values is a valid operation since Dates are internally represented as numbers. The compare function returns 0 if two dates: {date1} and {date2} are equivalent. If the value of the first object {date1} is less than the value of the second object {date2}, then -1 is returned. If {date1} is greater than {date2}, then +1 is returned.

### Function

Comparison of Function values is a valid operation. A function's object id is simply the function name itself. The compare function returns 0 if two function arguments have the same object id: {func1} and {func2}. If the object id of the first function {func1} is less than the object id of the second function {func2}, then -1 is returned. If the object id of the {func1} is greater than {func2}, then +1 is returned.

### Complex

Comparison of complex values is supported. The compare function returns 0 if two arguments have the same real and imaginary parts. If the first real value {cpx 1} is less than the the second real value {cpx2}, or, if the real parts are equal and the first imaginary value is less than the second imaginary value, then -1 is returned. Similarly, if the first real value of {cpx1} is greater than the real value of {cpx2}, or, if the real parts are equal and the first imaginary part is greater than the second, then +1 is returned.

### Lambda

The compare function tests if two Lambdas equal, greater than, or less than. Two Lambdas are equal, if they have the same variables, constants, and identical PcodeVectors. The compare function returns an Integer value: 0 if the Lambdas are equal, +1 if {Lambda1} is greater than {Lambda2}, and -1 if {Lambda1} is less than {Lambda2}.

### ObjectRepository

The compare function returns 0 if both Object Repository arguments are equivalent. Two Object Repositories are equal if they are the same file. If Object Repository1's filename {aGor1} is less than Object Repository2's filename {aGor2}, then -1 is returned. If Object Repository1's filename {aGor1} is greater than Object Repository2's filename {aGor2}, then +1 is returned.

Usage

Use the compare function when you wish to compare two arguments of the same Data Type and the result value needs to be represented as a numeric (0, 1 or -1). If a Boolean result is desired, then the Comparison Functions (=, <>, <, <=, >, >=) or the compareEQ, compareNE, compareGT, compareGE, compareLT, compareLE should be used instead.

### Lambda

The compare performs a deep compare and will determine if two Lambdas have the same variables, constants and pcode vectors. Usually if an Lambda is cloned (copied) from another Lambda and the cloned Lambda is assigned a new name, the compare will see that the newly cloned Lambda and original Lambda are equivalent and will return 0 (equal).

#### Syntax

Expression: (compare obj1 obj2 )

 Argument: Argument: Arguments Name Type Description obj1 Void Boolean Character Number Date Complex The first object to be compared. Must be a native data type (or complex). obj2 Void Boolean Character Number Date Complex The second object to be compared. Must be a native data type (or complex).

Returns: Returns 0 if the two objects are equal. Returns -1 if the obj1 is less than obj2. Returns +1 if obj1 is greater than obj2.

Expression: (compare string1 string2 )

 Argument: Argument: Arguments Name Type Description string1 String The first String to be compared string2 String The second String to be compared

Returns: Returns 0 if the two Strings are equal, Returns -1 if the string1 is less than string2, returns +1 if string1 is greater than string2.

Expression: (compare sym1 sym2 )

 Argument: Argument: Arguments Name Type Description sym1 Symbol The first Symbol to be compared sym2 Symbol The second Symbol to be compared

Returns: Returns 0 if the two Symbols are equal, Returns -1 if the sym1 is less than sym2, returns +1 if sym1 is greater than sym2.

Expression: (compare struct1 struct2 )

 Argument: Argument: Arguments Name Type Description struct1 Structure The first Structure to be compared struct2 Structure The second Structure to be compared

Returns: Returns 0 if the two Structures are equal, Returns -1 if the struct1 is less than struct2, returns +1 if struct1 is greater than struct2.

Expression: (compare dict1 dict2 )

 Argument: Argument: Arguments Name Type Description dict1 Dictionary The first Dictionary to be compared dict2 Dictionary The second Dictionary to be compared

Returns: Returns 0 if the two Dictionaries are equal, Returns -1 if the dict1 is less than dict2, returns +1 if dict1 is greater than dict2.

Expression: (compare dir1 dir2 )

 Argument: Argument: Arguments Name Type Description dir1 Directory The first Directory to be compared dir2 Directory The second Directory to be compared

Returns: Returns 0 if the two Directories are equal, Returns -1 if dir1 is less than dir2, returns +1 if dir1 is greater than dir2.

Expression: (compare vector1 vector2 )

 Argument: Argument: Arguments Name Type Description vector1 Vector The first Vector to be compared vector2 Vector The second Vector to be compared

Returns: Returns 0 if the two Vectors are equal, Returns -1 if vector1 is less than vector2, returns +1 if vector1 is greater than vector2.

Expression: (compare vector1 vector2 )

 Argument: Argument: Arguments Name Type Description vector1 Vector The first Vector to be compared vector2 Vector The second Vector to be compared

Returns: Returns 0 if the two Vectors are equal, Returns -1 if vector1 is less than vector2, returns +1 if vector1 is greater than vector2.

Expression: (compare vector1 vector2 )

 Argument: Argument: Arguments Name Type Description vector1 Vector The first Vector to be compared vector2 Vector The second Vector to be compared

Returns: Returns 0 if the two Vectors are equal, Returns -1 if vector1 is less than vector2, returns +1 if vector1 is greater than vector2.

Expression: (compare vector1 vector2 )

 Argument: Argument: Arguments Name Type Description vector1 Vector The first Vector to be compared vector2 Vector The second Vector to be compared

Returns: Returns 0 if the two Vectors are equal, Returns -1 if vector1 is less than vector2, returns +1 if vector1 is greater than vector2.

Expression: (compare vector1 vector2 )

 Argument: Argument: Arguments Name Type Description vector1 Vector The first Vector to be compared vector2 Vector The second Vector to be compared

Returns: Returns 0 if the two Vectors are equal, Returns -1 if vector1 is less than vector2, returns +1 if vector1 is greater than vector2.

Expression: (compare vector1 vector2 )

 Argument: Argument: Arguments Name Type Description vector1 Vector The first Vector to be compared vector2 Vector The second Vector to be compared

Returns: Returns 0 if the two Vectors are equal, Returns -1 if vector1 is less than vector2, returns +1 if vector1 is greater than vector2.

Expression: (compare vector1 vector2 )

 Argument: Argument: Arguments Name Type Description vector1 CpxVector The first CpxVector to be compared vector2 CpxVector The second CpxVector to be compared

Returns: Returns 0 if the two CpxVector are equal, Returns -1 if vector1 is less than vector2, returns +1 if vector1 is greater than vector2.

Expression: (compare vector1 vector2 )

 Argument: Argument: Arguments Name Type Description vector1 ShortVector The first ShortVector to be compared vector2 ShortVector The second ShortVector to be compared

Returns: Returns 0 if the two ShortVectors are equal, Returns -1 if vector1 is less than vector2, returns +1 if vector1 is greater than vector2.

Expression: (compare brick1 brick2 )

 Argument: Argument: Arguments Name Type Description brick1 Brick The first brick to be compared brick2 Brick The second Brick to be compared

Returns: Returns 0 if the two Bricks are equal, Returns -1 if brick1 is less than brick2, returns +1 if brick1 is greater than brick2.

Expression: (compare matrix1 matrix2 )

 Argument: Argument: Arguments Name Type Description matrix1 Matrix The first Matrix to be compared matrix2 Matrix The second Matrix to be compared

Returns: Returns 0 if Matrices are equal, Returns -1 if Matrix1 is less than Matrix2, returns +1 if Matrix1 is greater than Matrix2.

Expression: (compare nummatrix1 nummatrix2 )

 Argument: Argument: Arguments Name Type Description nummatrix1 NumMatrix The first NumMatrix to be compared nummatrix2 NumMatrix The second NumMatrix to be compared

Returns: Returns 0 if NumMatrices are equal, Returns -1 if NumMatrix1 is less than NumMatrix2, returns +1 if NumMatrix1 is greater than NumMatrix2.

Expression: (compare pair1 pair2 )

 Argument: Argument: Arguments Name Type Description pair1 Pair The first Pair to be compared pair2 Pair The second Pair to be compared

Returns: Returns 0 if Pairs are equal, Returns -1 if pair1 is less than pair2, returns +1 if pair1 is greater than pair2 .

Expression: (compare list1 list2 )

 Argument: Argument: Arguments Name Type Description list1 List The first List to be compared list2 List The second List to be compared

Returns: Returns 0 if Lists are equal, Returns -1 if list1 is less than list2, returns +1 if list1 is greater than list2.

Expression: (compare func1 func2 )

 Argument: Argument: Arguments Name Type Description func1 Function The first Function to be compared. func2 Function The second Function to be compared

Returns: Returns 0 if the two Function object ids are equal. Returns -1 if the func1 object id is less than func2 object id. Returns +1 if func1 object id is greater than func2 object id.

Expression: (compare Lambda1 Lambda2 )

 Argument: Argument: Arguments Name Type Description Lambda1 Lambda The first Lambda to be compared. Lambda2 Lambda The second Lambda to be compared

Returns: Returns 0 if the two Lambdas are equal. Returns -1 if the Lambda1 is less than Lambda2. Returns +1 if Lambda1 is greater than Lambda2.

Expression: (compare aGor1 aGor2 )

 Argument: Argument: Arguments Name Type Description aGor1 ObjectRepository The first Object Repository to be compared. aGor2 ObjectRepository The first Object Repository to be compared.

Returns: Returns 0 if the two Object Repositories are equal. Returns -1 if the aGor1 is less than aGor2. Returns +1 if aGor1 is greater than aGor2.

#### Examples

Here are a number of links to Lambda coding examples which contain this instruction in various use cases.

#### Argument Types

Here are the links to the data types of the function arguments.

 String Symbol Structure Dictionary Directory Boolean Number Date Complex Lambda Vector Brick Integer Matrix Pair List Void Character Function NumMatrix CpxVector FltVector ShortVector IntVector NumVector ObjVector BitVector ObjectRepository

Here are also a number of links to functions having arguments with any of these data types. 