It’s pretty clear that in all your test cases, the data is being treated as 
text.

If the cases where the data is in the format of “testxx” it will always be 
treated as a text string. Specifying just that portion of the variable that is 
numeric doesn’t override that.

In the case where you array contains just numbers, when you created the array 
you quoted all the numbers you assigned to the array thereby telling Rexx that 
you wanted those values treated as text strings.

Bottom line, just because something looks like a number doesn’t mean that Rexx 
has the context to treat it as a number.  For example if a variable looks like 
a number and then has an arithmetic operation performed on it, Rexx has enough 
context to treat the variable as a number.  
X='-2' <— text string
X=X+0 <— Ok, it’s now a number.
X=-2 <— Number
X=X||” ” <— Ok, you want a text string

As to:
> For all the other comparison operators, if both terms are numeric, the String 
> class does a numeric comparison (ignoring, for example, leading zeros

Rexx doesn’t know that it is a number until you tell it, it is a number.  You 
loaded the array with text strings, and didn’t tell it otherwise so it compared 
them as text strings.

Bruce

> On May 14, 2018, at 9:59 AM, Leslie Turriff <[email protected]> wrote:
> 
>       I need to sort an array of strings by their signed numeric suffixes, 
> but I'm 
> getting some strange results from sort and sortWith.  I have attached my V4.2 
> test program; together with its output.
> 
>       Section 5.1.3.8 of the Language Reference says,
> 'The strict comparison operators do not attempt to perform a numeric 
> comparison on the two operands.
> For all the other comparison operators, if both terms are numeric, the String 
> class does a numeric comparison (ignoring, for example, leading zeros— see 
> Section 10.4, “Numeric Comparisons”).'
> 
>       Section 10.4 says,
> 'Numeric values are compared by subtracting the two numbers (calculating the 
> difference) and then comparing the result with 0. That is, the operation:
>   A ? Z
> where ? is any numeric comparison operator, is identical with:
>   (A - Z) ? "0"
> It is, therefore, the difference between two numbers, when subtracted under 
> Rexx subtraction rules, that determines their equality.'
> 
>       Further, Section 10 says,
> 'Numbers can be expressed flexibly. Leading and trailing whitespace 
> characters 
> are permitted, and
> exponential notation can be used. Valid numbers are, for example:
> 
>  Example 10.1. Numbers
> 
>   12               /* a whole number                         */
>   "-76"            /* a signed whole number                  */
>     12.76             /* decimal places                      */
>     " + 0.003 "       /* blanks around the sign and so forth */
>     17.               /* same as 17                          */
>     .5                /* same as 0.5                         */
>     4E9               /* exponential notation                */
>     0.73e-7           /* exponential notation                */
> 
> A number in Rexx is defined as follows:
> 
>>> -+------------+--+----------------------+--+-digits--------+---------->
>      +-whitespace-+ +-sign--+------------+-+ +-digits.digits-+
>                                 +-whitespace-+    +-.digits-------+
>                                                   +-digits.-------+
>> --+------------+--------------------------------------------------><
>      +-whitespace-+
> 
> whitespace
>     are one or more blanks or horizontal tab characters.
> sign
>     is either + or -.
> digits
>     are one or more of the decimal digits 0-9.'
> 
>       However, in section 5.3.18, Sorting Arrays, we see that
> 'The sort method orders the strings by using the compareTo method of the 
> String class. The compareTo method knows how to compare one string to 
> another, and returns the values -1 (less than), 0 (equal), or 1 (greater 
> than) to indicate the relative ordering of the two strings.'
> 
> and
> 'Performs a sort comparison of the target string to the string argument. If 
> the two strings are equal, 0 is returned. If the target string is larger, 1 
> is returned. -1 if the string argument is the larger string.
> The comparison is performed starting at character n for length characters in 
> both strings. n must be a positive whole number. If n is omitted, the 
> comparison starts at the first character. length must be a non-negative whole 
> number. If omitted, the comparison will take place to the end of the target 
> string.'
> 
> which seems to imply a character comparison; and the examples for compareTo 
> include no numeric strings.
> 
>       Looking at the output from the test program, ooRexx seems to be sorting 
> signed numeric strings non-numerically (+ < - < 0), contrary to what would be 
> expected from section 10.  This seems to me to be a bug?  I would not expect 
> to have to write a custom comparator to re-implement a built-in mechanism.
> 
> Leslie
> 
> 
> 
> <testSort.txt><testSort.txt>------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! 
> http://sdm.link/slashdot_______________________________________________
> Oorexx-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to