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 )

Arguments Name Type Description
Argument:obj1Void Boolean Character Number Date Complex The first object to be compared. Must be a native data type (or complex).
Argument:obj2Void 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 )

Arguments Name Type Description
Argument:string1String The first String to be compared
Argument:string2String 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 )

Arguments Name Type Description
Argument:sym1Symbol The first Symbol to be compared
Argument:sym2Symbol 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 )

Arguments Name Type Description
Argument:struct1Structure The first Structure to be compared
Argument:struct2Structure 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 )

Arguments Name Type Description
Argument:dict1Dictionary The first Dictionary to be compared
Argument:dict2Dictionary 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 )

Arguments Name Type Description
Argument:dir1Directory The first Directory to be compared
Argument:dir2Directory 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 )

Arguments Name Type Description
Argument:vector1Vector The first Vector to be compared
Argument:vector2Vector 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 )

Arguments Name Type Description
Argument:vector1Vector The first Vector to be compared
Argument:vector2Vector 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 )

Arguments Name Type Description
Argument:vector1Vector The first Vector to be compared
Argument:vector2Vector 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 )

Arguments Name Type Description
Argument:vector1Vector The first Vector to be compared
Argument:vector2Vector 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 )

Arguments Name Type Description
Argument:vector1Vector The first Vector to be compared
Argument:vector2Vector 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 )

Arguments Name Type Description
Argument:vector1Vector The first Vector to be compared
Argument:vector2Vector 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 )

Arguments Name Type Description
Argument:vector1CpxVector The first CpxVector to be compared
Argument:vector2CpxVector 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 )

Arguments Name Type Description
Argument:vector1ShortVector The first ShortVector to be compared
Argument:vector2ShortVector 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 )

Arguments Name Type Description
Argument:brick1Brick The first brick to be compared
Argument:brick2Brick 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 )

Arguments Name Type Description
Argument:matrix1Matrix The first Matrix to be compared
Argument:matrix2Matrix 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 )

Arguments Name Type Description
Argument:nummatrix1NumMatrix The first NumMatrix to be compared
Argument:nummatrix2NumMatrix 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 )

Arguments Name Type Description
Argument:pair1Pair The first Pair to be compared
Argument:pair2Pair 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 )

Arguments Name Type Description
Argument:list1List The first List to be compared
Argument:list2List 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 )

Arguments Name Type Description
Argument:func1Function The first Function to be compared.
Argument:func2Function 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 )

Arguments Name Type Description
Argument:Lambda1Lambda The first Lambda to be compared.
Argument:Lambda2Lambda 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 )

Arguments Name Type Description
Argument:aGor1ObjectRepository The first Object Repository to be compared.
Argument:aGor2ObjectRepository 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.

++ += + /=
/ *= * --
-= - abortTransaction abs
acos add1 addMethod addi
appendWriteln append apply argCount
argFetch argument arithmetic asin
associate atan attachLibrarian avg
badd balance bcompareEQ bcompareGE
bcompareGT bcompareLE bcompareLT bcompareNE
bdiv beginTransaction binaryInsert binaryNand
binaryNor binaryNot binaryNxor binarySearch
bitToIntegerVector bitToNumberVector bitwiseAnd bitwiseNand
bitwiseNor bitwiseNot bitwiseNxor bitwiseOr
bitwiseShiftLeft bitwiseShiftRight bitwiseXor bmod
bmul boolean c::r cadd
callcc car ccompareEQ ccompareGE
ccompareGT ccompareLE ccompareLT ccompareNE
cdiv cdr char character
checkPointTransaction class clean clear
closeLog cmod cmul code
commitTransaction compareEQ compareGE compareGT
compareLE compareLT compareNE compare
comparison compile complex compress
conjugate cons copy cos
cosh count csub date
day days360 debugBrowsableProcs debugDetective
debugEval debug decode defchild
defclass define(macro) defineStructure define
defmacro defmethod deforphan defriend
defstruct defun deg deleteRows
delete detachLibrarian dimension disassemble
display divi downcase encode
evalInSyncLocalContext eval exit exp
exportCsv exportSbf exportTab expt
fact fdisplay fieldsOf fileClose
fileCopy fileDir fileDisplay fileEraseDir
fileErase fileExists fileMakeDir fileOpen
fileReadAll fileReadRecord fileRead fileResize
fileSeek fileSizeOf fileWriteAll fileWrite
filewriteln findBlock find floor
fraction freeBlock gc gcd
getGlobalValue getRecursionCount getSymbolTable getTickCount
globalBinding hashString hour iadd
icompareEQ icompareGE icompareGT icompareLE
icompareLT icompareNE idiv imaginary
imod importCsv importSbf importTab
imul insertRows insert inside
inspect integer isAtom isBitVector
isBoolean isBound isByteVector isCharAlphabetic
isCharAlphanumeric isCharLowercase isCharName isCharNumeric
isCharUppercase isCharWhitespace isChar isCharacter
isClass isComplex isDate isDictionary
isDirectory isEqual isError isEven
isExact isFloatVector isIdentical isImmediate
isInexact isInside isIntegerVector isInteger
isLambda isMatrix isMember isMoney
isNegative isNull isNumberMatrix isNumberVector
isNumber isObjectVector isObject isOdd
isPair isPcodeVector isPositive isString
isStructure isSymbol isText isTransaction
isType isVector isZero isub
julian kurtosis lambda last
lcm left length lisp
list loadModule loadRepository loadWorkspace
lock log10 log2 logConsole
log logbase macroReplace makeDictionary
makeGaussianMatrix makeGramMatrix makeLambda makeQuotedList
makeQuotedSymbol makeStructure map mapc
matrixGaussianEliminate matrixGaussianSubstitute max median
member methodsOf mid min
minute mod modi money
month morph muli myself
nadd ncompareEQ ncompareGE ncompareGT
ncompareLE ncompareLT ncompareNE ndiv
new nmod nmul now
nsub number objectToDictionary objectToDirectory
objectToList objectToMatrix objectToNumMatrix objectToNumVector
objectToStructure objectToVector offset onError
openLog pair parent parse
pi pointer preAllocateFixedMemoryBlocks product
proplist proprecord putprop qt
quit quote rad random
randomize range rank real
refAttributes refLibrarian refValues ref
remProp remove rename replace
rept reset resize reverse
right round run saveImmediate
saveModule saveObject saveRepository saveWorkspace
second send setAttributes setBlock
setCar setCdr setLastCdr set
setf setq sigmoid sign
sin sinh sizeof skew
sleep sort sql sqrt
srandom stdev stdevp stringCiEQ
stringCiGE stringCiGT stringCiLE stringCiLT
stringCiNE stringFill stringToBVector stringToVector
string sub1 subi submit
substitute substringCiEQ substringCiGE substringCiGT
substringCiLE substringCiLT substringCiNE substringEQ
substringFill substringGE substringGT substringLE
substringLT substringNE substring sum
sumsqr super svmRegression symbolToTypeCode
symbol systemCheck system tan
tanh text time today
trim type uniqueInsert unlock
upcase var varp vectorBinaryInnerProduct
vectorBipolarInnerProduct vectorCosineInnerProduct vectorCubeInnerProduct vectorDelete
vectorExpInnerProduct vectorFill vectorInnerProduct vectorLogInnerProduct
vectorQuartInnerProduct vectorQuintInnerProduct vectorSigmoidInnerProduct vectorSineInnerProduct
vectorSquareInnerProduct vectorTanInnerProduct vectorTanhInnerProduct version
writelg writeln year

Analytic Information Server (AIS)

AIS Component Systems

  • Smartbase Engine
  • QT C++ Libraries
  • MySQL Relational Database
  • AIS Lisp Libraries
  • Rapid Analytic Demo IDE