Intended to file a bug for this, just to find an open bug already:
<https://sourceforge.net/p/oorexx/bugs/1365/> from Erich, dated February 2016.

It seems that the implementation of the mixin-class
"interpreter\RexxClasses\CoreClasses.orx\Orderable" is wrong in its forwarding 
of the  "=" method to
"==" (strict equal):

    -- compare two instances -- == and \== don't raise an error if these -- are 
not of the same
    type, they will apply object -- comparison rules for that. ::METHOD "==" 
use strict arg other if
    \other~isa(self~class) then do return .false end return 
self~compareTo(other) == 0 ::METHOD "="
    -- this is equivalent of "==" forward message("==")

The same problem exists with the unequality methods:

    -- compare two instances ::METHOD "\==" use strict arg other if 
\other~isa(self~class) then do
    return .true end return self~compareTo(other) \== 0 ::METHOD "\=" -- this 
is equivalent of "\=="
    forward message("\==")


A possible fix for (the entire class, as there are further little problems with 
strict comparisons)
could be (changes highlighted with the colour blue and a line comment starting 
with "--rgf"):

    -- A mixin class for easily adding comparison methods to a -- class ::CLASS 
'Orderable' PUBLIC
    MIXINCLASS Object -- perform an ordered comparison of two objects ::METHOD 
compareTo ABSTRACT --
    compare two instances -- == and \== don't raise an error if these -- are 
not of the same type,
    they will apply object -- comparison rules for that. ::METHOD "==" use 
strict arg other if
    \other~isa(self~class) then do --rgf, strict comparison means also of the 
same type return
    .false end return self~compareTo(other) == 0 -- compare two instances 
::METHOD "\==" use strict
    arg other if \other~isa(self~class) then do --rgf, strict comparison means 
also of the same type
    return .true end return self~compareTo(other) \== 0 ::METHOD "=" use strict 
arg other return
    self~compareTo(other) = 0--rgf, just carry out the comparison ::METHOD "\="
    use strict arg other return self~compareTo(other) \= 0--rgf, just carry out 
the comparison
    ::METHOD "<>" -- this is equivalent of "\=" --rgf forward message("\=") 
--rgf ::METHOD "><"  -- this is equivalent of "\=" --rgf forward message("\=") 
--rgf ::METHOD "<" use strict arg
    other return self~compareTo(other) < 0 ::METHOD "<=" use strict arg other 
return
    self~compareTo(other) <= 0 ::METHOD "\>" use strict arg other return 
self~compareTo(other) <= 0
    ::METHOD "<<" use strict arg other  if \other~isa(self~class) then do 
--rgf, strict comparison means also of the same type return
    .false  return self~compareTo(other) < 0 ::METHOD "<<=" use strict arg other
    if \other~isa(self~class) then do --rgf, strict comparison means also of 
the same typereturn
    .false  return self~compareTo(other) <= 0 ::METHOD "\>>" use strict arg 
other if
    \other~isa(self~class) then do --rgf, strict comparison means also of the 
same typereturn .false
     return self~compareTo(other) <= 0 ::METHOD ">" use strict arg other return
    self~compareTo(other) > 0 ::METHOD ">=" use strict arg other return 
self~compareTo(other) >= 0
    ::METHOD "\<" use strict arg other return self~compareTo(other) >= 0 
::METHOD ">>" use strict
    arg other if \other~isa(self~class) then do --rgf, strict comparison means 
also of the same type
    return .false  return self~compareTo(other) > 0 ::METHOD ">>=" use strict 
arg other
    if \other~isa(self~class) then do --rgf, strict comparison means also of 
the same type return
    .false   return self~compareTo(other) >= 0 ::METHOD "\<<" use strict arg 
other if
    \other~isa(self~class) then do --rgf, strict comparison means also of the 
same type return
    .false  return self~compareTo(other) >= 0

---rony



On 17.07.2016 18:27, Rony G. Flatscher wrote:
>
> Hi there,
>
> while experimenting with a class (JSON_Boolean) that inherits the class 
> "Orderable" and implements
> the abstract method "compareTo" and a "makestring" method to yield "0" for 
> .false and "1" for
> .true, I have run into a problem that may be obvious to others, but currently 
> I am stuck: it seems
> that relational comparisons only cause the "compareTo"-method to be invoked, 
> if both operands are
> instances of .JSON_Boolean!
>
> So far I thought that a relational comparison like "(a=b)" would cause a 
> message like "(a~'='(b))"
> to be carried out by the interpreter which in the case of inheriting from 
> "Orderable" would
> ultimately cause the "compareTo"-method of "a" to be invoked in its "=" 
> method supplying "b" as
> the argument "other".
>
> Therefore I would expect that the "compareTo"-method gets invoked via 
> "Orderable" if the left hand
> side of the comparison is an object of type .JSON_Boolean. However, this is 
> not the case!
>
> Here is a small snippet of a program and the values the comparisons generate 
> going as line
> comments in the appropriate statements:
>
>     vtrue =.json_boolean~new(.true)  say "vtrue=1:" (vtrue=1) -- yields: 0 
> (vtrue~compareTo() NOT
>     invoked! expecting to yield 1 !) say "1=vtrue:" (1=vtrue) -- yields: 1 
> (invoked
>     vtrue~makeString()) say "vtrue=vtrue:" (vtrue=vtrue) -- yields: 1 
> (vtrue~compareTo() got
>     invoked) ... cut ...
>
> What surprises me is that the expression "(vtrue=1)" does not cause a message 
> like "vtrue~'='(1)"
> to be carried out which then would carry out a message like 
> "vtrue~compareTo(1)" in Orderable's
> "=" method!
>
> If both operands are of type JSON_Boolean, then - and only then - is 
> JSON_Boolean's
> "compareTo"-method triggered.
>
> The (shortened) program used for these tests is enclosed, followed by the 
> output running it on
> ooRexx 4.2.0 and ooRexx 5.0.0alpha.
>
> Maybe I am overlooking something obvious, hence asking whether my assumptions 
> are correct and if
> not, what the exact rules are?
>
> ---rony
>
> P.S.: Test program and the output of running the program on 32-bit ooRexx 
> 4.2.0 and 5.0.0alpha.
>
> "test.rex":
>
>     parse version v say "***" v "***" vtrue =.json_boolean~new(.true) say 
> "vtrue ="vtrue say "---"
>     -- as JSON_Boolean inherits Orderable and implements a compareTo-method, 
> shouldn't that be
>     invoked? say "vtrue=1:" */(vtrue=1)/* say "1=vtrue:" */(1=vtrue)/* say 
> "---" say
>     "vtrue=vtrue:" /*(vtrue=vtrue*//*)*/ *::class "JSON_Boolean" public 
> inherit /orderable/*
>     ::attribute value get -- getter method ::attribute value set -- setter 
> method, accpeting
>     ooRexx logical values in a relaxed, JSON related form expose value use 
> strict arg val -- test
>     whether a value was supplied that we accept as a boolean value, i.e. one 
> of "0", "1" or -- one
>     of a caseless "true", ".true", "false" or ".false" if "0 1 true false 
> .true
>     .false"~caselessWordPos(val)=0 then raise syntax 88.900 array ("Argument 
> must be one of '0',
>     'false', '.false', '1', 'true' or '.true', found:" val) value=("0 false
>     .false"~caselessWordPos(val)=0) -- .true, if no false values supplied 
> ::method init use strict
>     arg val self~value=val -- determine and assign boolean value using the 
> defined attribute
>     setter method */::method compareTo/* -- implementation for .orderable 
> class: must return -1 if
>     other greater, 0 if same, 1 otherwise expose value use strict arg other 
> -- other must be a
>     Boolean value .traceOutput~say("//" 
> self~objectname"@"self~identityHash"::compareTo()
>     other~objectname="other~objectName) if other~isA(.JSON_Boolean) then 
> otherValue=other~value
>     else otherValue=other~request("string") -- request the string value if 
> otherValue=.nil then
>     raise syntax 88.900 array ("Argument other ["other"] has no 'MAKESTRING' 
> method")
>     .traceOutput~say("\\" self~objectname"@"self~identityHash"::compareTo() 
> otherValue="otherValue
>     "self~value:" value) if otherValue > value then return -1 if otherValue = 
> value then return 0
>     return 1 */::method makestring/* -- allow instances of this class to be 
> plug in replacement
>     for ooRexx logical values expose value
>     .traceOutput~say(self~objectname"@"self~identityHash"::MAKEstring, 
> value="value) return value
>
> Output of running "test.rex" on ooRexx 4.2.0:
>
>     G:\test\oorexx\json>rexx test.rex *** */REXX-ooRexx_4.2.0(MT)_32-bit 6.04 
> 22 Feb 2014/* *** a
>     JSON_Boolean@264727158::MAKEstring, value=1 vtrue =1 --- vtrue=1: 0 a
>     JSON_Boolean@264727158::MAKEstring, value=1 1=vtrue: 1 --- // a
>     JSON_Boolean@264727158::compareTo() other~objectname=a JSON_Boolean \\ a
>     JSON_Boolean@264727158::compareTo() otherValue=1 self~value: 1 
> vtrue=vtrue: 1
>
> Output of running "test.rex" on the latest ooRexx 5.0.0:
>
>     F:\download\Rexx\ooRexx\alpha500\work\bin_small>rexx 
> g:\test\oorexx\json\test.rex ***
>     */REXX-ooRexx_5.0.0(MT)_32-bit 6.05 14 Jun 2016/* *** a 
> JSON_Boolean@-2109450313::MAKEstring,
>     value=1 vtrue =1 --- vtrue=1: 0 a JSON_Boolean@-2109450313::MAKEstring, 
> value=1 1=vtrue: 1 ---
>     // a JSON_Boolean@-2109450313::compareTo() other~objectname=a 
> JSON_Boolean \\ a
>     JSON_Boolean@-2109450313::compareTo() otherValue=1 self~value: 1 
> vtrue=vtrue: 1
>
>
>
>
>
> ------------------------------------------------------------------------------
> What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
> patterns at an interface-level. Reveals which users, apps, and protocols are 
> consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
> J-Flow, sFlow and other flows. Make informed decisions using capacity planning
> reports.http://sdm.link/zohodev2dev
>
>
> _______________________________________________
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel

-- 
--
__________________________________________________________________________________

Prof. Dr. Rony G. Flatscher
Department Informationsverarbeitung und Prozessmanagement
Institut für Betriebswirtschaftslehre und Wirtschaftsinformatik
D2-C 2.086
WU Wien
Welthandelsplatz 1
A-1020  Wien/Vienna, Austria/Europe

http://www.wu.ac.at
__________________________________________________________________________________





------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to