1. compare() and equal()

This bugs me a bit:

compare can do this:
x = compare({1,2,{3,{4}},5}, {2-1,1+1,{3,{4}},6-1})
-- identical, x is 0

but if i use equal there, it faults out with an error about a sequence being in
there.

Also, if equal() is true, it returns boolean true, but if compare() is true, it
returns
boolean false.

Robert, can equal() be made more like compare() when it comes to those nested 
subsequences?

Kat

new topic     » topic index » view message » categorize

2. Re: compare() and equal()

> This bugs me a bit:
>
> compare can do this:
> x = compare({1,2,{3,{4}},5}, {2-1,1+1,{3,{4}},6-1})
> -- identical, x is 0
>
> but if i use equal there, it faults out with an error about a sequence being
> in there.
>
> Also, if equal() is true, it returns boolean true, but if compare() is true,
> it returns
> boolean false.
>
> Robert, can equal() be made more like compare() when it comes to those nested 
> subsequences?
>
> Kat

The idea of equal() was to provide an easier version of compare() for
checking if 2 sequences are equal so people didn't get confused with having to
do:

if compare(x,y) = 0 then

Also:

? compare({1,2,{3,{4}},5}, {2-1,1+1,{3,{4}},6-1})
? equal({1,2,{3,{4}},5}, {2-1,1+1,{3,{4}},6-1})

Works fine for me...

Thomas Parslow (PatRat) ICQ #:26359483
Rat Software
http://www.rat-software.com/
Please leave quoted text in place when replying

new topic     » goto parent     » topic index » view message » categorize

3. Re: compare() and equal()

Dear Eu users:

On this subject, I like Eu because of
Eu's semantic logic and syntax.

Try please program below, remember
compare() returns -1 or 0 or +1
equal()   returns  1 or 0 

-------------------------program
sequence a,b,c,d,e
integer n

a={1,1}
b={2,2}
c={3,3}
d={4,4}
e={1,1}

n=1    if compare(a,b)=+1 then
n=2 elsif compare(a,c)=-1 then ---< non-equal a<c
n=3 elsif compare(a,e)= 0 then 
n=4 elsif compare(d,a)=+1 then 
n=5 elsif compare(a,c)=+1 then 
n=6 end if

?n-1

n=1    if compare(a,b)=+1 then
n=2 elsif compare(a,c)=+1 then 
n=3 elsif compare(a,c)= 0 then 
n=4 elsif compare(d,a)=+1 then ---< non-equal d>a
n=5 elsif compare(a,c)=+1 then 
n=6 end if

?n-1
  
------------
function same(object x, object y)
 return compare(x,y)=0
end function

n=1    if same(a,b) then
n=2 elsif same(a,c) then
n=3 elsif same(a,e) then  ---< equal
n=4 elsif same(a,d) then
n=5 elsif same(a,c) then
n=6 end if

?n-1

------------
function other(object x, object y)
 return compare(x,y)!=0
end function

n=1    if other(a,b) then
n=2 elsif other(a,c) then
n=3 elsif other(a,e) then  ---< equal
n=4 elsif other(a,d) then
n=5 elsif other(a,c) then
n=6 end if

?n-1
--------------

n=1    if equal(a,b) then
n=2 elsif equal(a,c) then
n=3 elsif equal(a,e) then ---< equal
n=4 elsif equal(a,d) then
n=5 elsif equal(a,c) then
n=6 end if

?n-1
-------------------------
function different(object x, object y)
 return not equal(x,y)
end function

n=0
   if different(a,b) then n=1
elsif different(a,c) then n=2
elsif different(a,e) then n=3  ---< equal
elsif different(a,d) then n=4
elsif different(a,c) then n=5
end if 

?n
---------------------end of program


And so on, bigger(), lager(), smaller(),
lesser(), not_bigger(), not_lager(),
not_smaller(), not_lesser()...

Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » goto parent     » topic index » view message » categorize

4. Re: compare() and equal()

kat wrote:

> non-reproducable bugs...

Perhaps you have memory errors? That might account for some of the odd
behaviors. I've seen similar problems intermittantly on my machine: I could
reproduce it again and again, but on reboot it would return to normal. This
would typically happen after some errant code went dancing through memory.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu