When a class inherits Comparable and Orderable, I'm expecting it to call
the compareTo() method for any comparison operator.
This seems to happen for all cases, except when the operator is "equal" or
"not equal" and the compared objects are of different classes: in that
case, compareTo() isn't called (and neither is string() called)
This example
signal on nostring
n = .n~new(123)
say "n = .n~new(123)" (n = .n~new(123))
say "n~= .n~new(123)" (n~"="(.n~new(123)))
say "n <> .n~new(123)" (n <> .n~new(123))
say "n >= .n~new(123)" (n >= .n~new(123))
say "n <= .n~new(123)" (n <= .n~new(123))
say "n = 123 " (n = 123 )
say "n~= 123 " (n~"="(123) )
say "n <> 123 " (n <> 123 )
say "n >= 123 " (n >= 123 )
say "n <= 123 " (n <= 123 )
::class n inherit orderable comparable
::method init
expose n
use arg n
::method string
expose n
call charout , "string("n") "
return n
::method compareTo
expose n
use arg other
call charout , "compareTo("n"," other~class~id") "
return (n - other~string)~sign
gives the output:
compareTo(123, N) string(123) n = .n~new(123) 1
compareTo(123, N) string(123) n~= .n~new(123) 1
compareTo(123, N) string(123) n <> .n~new(123) 0
compareTo(123, N) string(123) n >= .n~new(123) 1
compareTo(123, N) string(123) n <= .n~new(123) 1
n = 123 0
n~= 123 0
n <> 123 1
compareTo(123, String) n >= 123 1
compareTo(123, String) n <= 123 1
Is this working as intended or a bug?
------------------------------------------------------------------------------
_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel