Loading

SORTWITH


lists gts
Since v2.2.0
Available on all platforms
See also

The SORTWITH function sorts a list according to a value returned by a comparison macro.

The comparison macro is given 2 elements of the list and return a LONG which can be represented on 32 bits. The returned value must be negative, zero or positive if the deepest element in the stack is respectively strictly less than, equal to or strictly more than than the element on the stack.

Signature

Examples

// // Create 3 random Geo Time Series // 1 3 <% NEWGTS SWAP TOSTRING RENAME 1 100 <% NaN NaN NaN RAND ADDVALUE %> FOR %> FOR // // Also add a Geo Time Series with the same mean than the last // created GTS but with a lower std. // CLONE DUP false MUSIGMA DROP 'mu' STORE '4' RENAME 101 NaN NaN NaN $mu ADDVALUE 102 NaN NaN NaN $mu ADDVALUE 4 ->LIST // Add mean and std as attributes, only here to check the result. <% DROP DUP false MUSIGMA [ 'mu' 'sigma' ] STORE { 'mu' $mu TOSTRING 'sigma' $sigma TOSTRING } SETATTRIBUTES %> LMAP // // Sort the GTS according to their mean and, if equal, to their standard deviation // <% [ 'a' 'b' ] STORE $a false MUSIGMA [ 'a_mu' 'a_sigma' ] STORE $b false MUSIGMA [ 'b_mu' 'b_sigma' ] STORE $a_mu $b_mu < <% -1 %> IFT $a_mu $b_mu > <% 1 %> IFT $a_mu $b_mu == <% $a_sigma $b_sigma < <% -1 %> IFT $a_sigma $b_sigma > <% 1 %> IFT $a_sigma $b_sigma == <% 0 %> IFT %> IFT %> SORTWITH