sort

 

 

Overview

The sort function returns a sorted copy of the specified Structure, Dictionary, Directory, Vector, Matrix, Pair or List argument {target} in the order specified by the argument predicate {predicate}. If the optional Boolean argument {true} is present, the sort function does not sort the specified target; but instead, returns a sorted integer vector of indices into the specified target.

Usage

The sort function sorts all the elements in a vector and returns the sorted version of the Vector. The sort function is destructive except for the option containing the keyword {true}, which returns a new sorted integer vector.

Structure

The sort function can be used to sort an AIS Object by the values or by keys, destructively or non-destructively.

Dictionary

The sort function can be used to sort an AIS Object by the values or by keys, destructively or non-destructively.

Directory

The sort function can be used to sort an AIS Object by the values or by keys, destructively or non-destructively.

List

The sort function can be used to sort an AIS Object by the values or by keys, destructively or non-destructively.

Matrix

The sort function sorts all the elements in a Matrix and returns the sorted version of the Matrix . The sort function is destructive except for the option containing the keyword {true}, which returns a new sorted integer Matrix .

NumMatrix

The sort function sorts all the elements in a NumMatrix and returns the sorted version of the NumMatrix . The sort function is destructive except for the option containing the keyword {true}, which returns a new sorted integer NumMatrix .

 

Syntax


Expression:

(sort vector predicate )

(sort vector predicate true))


Arguments Name Type Description
Argument:vector Vector FltVector ShortVector IntVector NumVector ObjVector BitVector The vector to be sorted
Argument:predicateWord predicate > means sort in descending order, predicate < means sort in ascending order
Argument:true Boolean Optional argument: If present it means to return an integer vector containing sorted indices to the vector.

Returns:

The sorted Vector.




Expression:

(sort struct predicate )

(sort struct predicate true))


Arguments Name Type Description
Argument:struct Structure The structure to be sorted
Argument:predicateWord predicate > means sort in descending order, predicate < means sort in ascending order
Argument:true Boolean Optional argument: If present it means to return an integer vector containing sorted indices to the structure.

Returns:

If {true} is present, an integer vector containing the sorted indices to the structure is returned. If {true} is not present, the sorted structure is returned.




Expression:

(sort dict predicate )

(sort dict predicate true))


Arguments Name Type Description
Argument:dict Dictionary The dictionary to be sorted
Argument:predicateWord predicate > means sort in descending order, predicate < means sort in ascending order
Argument:true Boolean Optional argument: If present it means to return an integer vector containing sorted indices to the dictionary.

Returns:

If {true} is present, an integer vector containing the sorted indices to the dictionary is returned. If {true} is not present, the sorted dictionary is returned.




Expression:

(sort dir predicate )

(sort dir predicate true))


Arguments Name Type Description
Argument:dir Directory The directory to be sorted
Argument:predicateWord predicate > means sort in descending order, predicate < means sort in ascending order
Argument:true Boolean Optional argument: If present it means to return an integer vector containing sorted indices to the directory.

Returns:

If {true} is present, an integer vector containing the sorted indices to the directory is returned. If {true} is not present, the sorted directory is returned.




Expression:

(sort matrix predicate )

(sort matrix predicate true))


Arguments Name Type Description
Argument:matrix Matrix The Matrix to be sorted
Argument:predicateWord predicate > means sort in descending order, predicate < means sort in ascending order
Argument:true Boolean Optional keyword, if present, an integer Vector containing stored indices to the Matrix to be sorted.

Returns:

The sorted Matrix is returned.




Expression:

(sort nummatrix predicate )

(sort nummatrix predicate true))


Arguments Name Type Description
Argument:nummatrix NumMatrix The NumMatrix to be sorted
Argument:predicateWord predicate > means sort in descending order, predicate < means sort in ascending order
Argument:true Boolean Optional keyword, if present, an integer Vector containing stored indices to the NumMatrix to be sorted.

Returns:

The sorted NumMatrix is returned.




Expression:

(sort list predicate )

(sort list predicate true))


Arguments Name Type Description
Argument:list List The List to be sorted
Argument:predicateWord predicate > means sort in descending order, predicate < means sort in ascending order
Argument:true Boolean Optional keyword, if present, an integer Vector containing stored indices to the List to be sorted.

Returns:

The sorted Matrix, or the integer Vector in case the argument {true} is specified, is returned.



 

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.

Structure Dictionary Directory List
NumMatrix ShortVector Matrix Vector
String Text Integer Boolean

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

++ += + /=
/ *= * --
-= - abortTransaction addMethod
addi appendWriteln append apply
associate avg badd balance
bcompareEQ bcompareGE bcompareGT bcompareLE
bcompareLT bcompareNE bdiv beginTransaction
binaryInsert binaryNand binaryNor binaryNot
binaryNxor binarySearch bitToNumberVector bitwiseAnd
bitwiseNand bitwiseNor bitwiseNot bitwiseNxor
bitwiseOr bitwiseShiftLeft bitwiseShiftRight bitwiseXor
bmod bmul boolean c::r
cadd 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 compress cons
copy count csub date
day days360 debugBrowsableProcs debugDetective
debugEval debug defineStructure defstruct
deleteRows delete dimension disassemble
display divi downcase encode
evalInSyncLocalContext eval exit exportCsv
exportSbf exportTab 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 getRecursionCount hashString
hour iadd icompareEQ icompareGE
icompareGT icompareLE icompareLT icompareNE
idiv 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 last
lcm left length lisp
list loadModule loadRepository loadWorkspace
logConsole macroReplace makeDictionary makeGaussianMatrix
makeGramMatrix makeQuotedList makeQuotedSymbol makeStructure
map mapc matrixGaussianEliminate matrixGaussianSubstitute
max median member methodsOf
mid min minute mod
modi money month morph
muli ncompareEQ ncompareGE ncompareGT
ncompareLE ncompareLT ncompareNE new
number objectToDictionary objectToDirectory objectToList
objectToMatrix objectToNumMatrix objectToNumVector objectToStructure
objectToVector offset onError openLog
pair parent parse pointer
preAllocateFixedMemoryBlocks product proplist proprecord
putprop qt quit quote
random randomize range rank
refAttributes 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 sizeof skew sort
sql sqrt srandom stdev
stdevp stringCiEQ stringCiGE stringCiGT
stringCiLE stringCiLT stringCiNE stringFill
stringToBVector stringToVector string 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
text time trim type
uniqueInsert 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