mIRC Homepage

$min add'l sort orders

Posted By: maroon

$min add'l sort orders - 27/09/20 05:05 PM

Suggestion to have an additional .prop's for $min and $max which use the default $sorttok and $sorttokcs orders when they don't use the $3 switch. The current mappings for $min appear to be:

Quote

no .prop = $sorttok 'n' numeric
.text = $sorttok 'a' alphanumeric
.textcs = $sortokcs 'a' alphanumeric
.nick = $sorttok 'c' channel

missing = $sorttok no-switch
missing = $sorttokcs no-switch


Code
alias minmaxsort {
  if ($1- == $null) var -s %list a 0 b \ 1 ! A . ~ 2 @ 11 | else var %list $1-
  echo -a default : $sorttok(  %list,32)
  echo -a alphanum: $sorttok(  %list,32,a) min: $min(%list).text   max: $max(%list).text
  echo -a numeric : $sorttok(  %list,32,n) min: $min(%list)        max: $max(%list)
  echo -a nicklist: $sorttok(  %list,32,c) min: $min(%list).nick   max: $max(%list).nick
  echo -a alnum cs: $sorttokcs(%list,32,a) min: $min(%list).textcs max: $max(%list).textcs
  var -s %list a 0 b \ 1 A  ~ 2 11
  echo -a default :: $sorttok(    %list,32)
  echo -a defaultcs: $sorttokcs(  %list,32)
  echo -a alpha num: $sorttok(    %list,32,a) min: $min(%list).text   max: $max(%list).text
  echo -a alnum cs : $sorttokcs(  %list,32,a) min: $min(%list).textcs max: $max(%list).textcs
  var -s %list a \ A
  echo -a default  : $sorttok(    %list,32)
  echo -a defaultcs: $sorttokcs(  %list,32)
}
Posted By: maroon

Re: $min add'l sort orders - 08/11/20 06:33 AM

Thanks. It looks like we now have

.alpha = $sorttok no-switch
.alphacs = $sorttokcs no-switch

Observation about the newly added props.

1. I can't find any difference in the output between the new .props $min().text $max().text vs the prior .props of $min().alnum $max().alnum, so I'm wondering if these are 2 names for the same thing or is there an edge-case I'm missing?

2. When comparing against aliases that used $sorttok to find min/max, where $min would be the 1st token and $max would be the final token, I've not found a variance in how $min behaves, but there is an edge case in how $max differs.

The behavior of sorttok has always been that tokens with equivalent values are placed into the output in the same order as in the input string. So, when $sorttok was being used as a replacement for $max, it returned max as the last token. When there are several tokens which are either case-insensitive or numerical equivalents, $max is returning the first of the equivalents instead of the last of the equivalents.

For numerical sorts, where text evaluates as zero, if the string has no numeric tokens, the $max result is always the 1st text token, causing $max to always match $min:

//var -s %s $r(a,z) $r(a,z) $r(a,z) , %s %s $upper(%s) | echo -a $max(%s) and $min(%s) are both the first of $sorttok(%s,32,n)

typical result:
* Set %s to e i a
* Set %s to e i a E I A
e and e are both the first of e i a E I A

For case-insensitive text sorting, if the max value has upper/lowercase equivalents, the first equivalent token is the max instead of the last equivalent token:

//var %s1 Z z , %s2 z Z | echo -a min $min(%s1).text and max $max(%s1).text or min $min(%s2).text and max $max(%s2).text vs sorttok: $sorttok(%s1,32,a) or $sorttok(%s2,32,a)

result: Z and Z or z and z vs sorttok: Z z or z Z

I can see the logic of both definitions for max, and I'm guessing that the change to the $sorttok style behavior would be a line of code that's similar to "if (next_token > max) then max = next_token" and change the > into >=
Posted By: Khaled

Re: $min add'l sort orders - 14/11/20 02:13 PM

Quote
1. I can't find any difference in the output between the new .props $min().text $max().text vs the prior .props of $min().alnum $max().alnum, so I'm wondering if these are 2 names for the same thing or is there an edge-case I'm missing?

I added .alnum/.alpha to make it clear what the options are. I will be removing .text from the documentation.

Quote
2. When comparing against aliases that used $sorttok to find min/max, where $min would be the 1st token and $max would be the final token, I've not found a variance in how $min behaves, but there is an edge case in how $max differs.

Here is what is happening:

$min(z Z) returns a case-insensitive (sorted from smallest to largest) list "z Z" and returns the first item.
$min(Z z) returns a case-insensitive (sorted from smallest to largest) list "Z z" and returns the first item.

$max(z Z) returns a case-insensitive (sorted from largest to smallest) list "z Z" and returns the first item.
$max(Z z) returns a case-insensitive (sorted from largest to smallest) list "Z z" and returns the first item.

$sorttok(z Z,32,a) returns a case-insensitive (sorted from smallest to largest) list "z Z".
$sorttok(Z z,32,a) returns a case-insensitive (sorted from smallest to largest) list "Z z".
© 2020 mIRC Discussion Forums