1. RE: compare() and equal()

Hi Kat,
I just did this ...

? 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})

...
and I got displayed ...

0
1

which is exactly what I'd expect. There was no error message or the like.

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

But compare() can *never* be true as it does not return a true/false
indicator. It isn't meant to. It just tells if parameter#1 is less than,
equal to, or greater than parameter#2. And this is not a boolean thing.

-----------
cheers,
Derek Parnell

new topic     » topic index » view message » categorize

2. RE: compare() and equal()

On 8 Apr 2001, at 23:56, Derek Parnell wrote:


> 
> Hi Kat,
> I just did this ...
> 
> ? 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})
> 
> ...
> and I got displayed ...
> 
> 0
> 1
> 
> which is exactly what I'd expect. There was no error message or the like.

Well, i just changed a bunch of these:
if equal(a,b) then

to:
if (compare(a,b) = 0) then

because the nested sequences in the equal() line were crashing the program! 
The compare() line runs fine now.
 
> > Also, if equal() is true, it returns boolean true, but if
> > compare() is true, it returns
> > boolean false.
> >
> 
> But compare() can *never* be true as it does not return a true/false
> indicator. It isn't meant to. It just tells if parameter#1 is less than,
> equal to, or greater than parameter#2. And this is not a boolean thing.

It returns zero or non-zero, and zero equates to false in a boolean compare. 
Equal() returns 1 (true) or 0 (false) the same way, but the true-1 in equal() 
and the true-0 in compare() feels too odd.

Kat

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

3. RE: compare() and equal()

>It returns zero or non-zero, and zero equates to false in a boolean compare. 
>Equal() returns 1 (true) or 0 (false) the same way, but the true-1 in equal() 
>and the true-0 in compare() feels too odd.
>
>Kat

As Patrat mentioned, Rob included equal() because a number
of people requested it to get rid of lots of :

if not compare(a,b) then .....

lines. Which was the origional way of testing for identical 
sequences. If you use it as a boolean, then compare works 
perfectly as a test for inequality...

i.e.   if a!=b then ...
       if compare(a,b) then...

          vs.

       if a=b then ....
       if equal(a,b) then...

When used in this fashion, compare will either return
1 or -1 (both of which equate to TRUE in Eu) if the sequences
are diffrent, of 0 (FALSE) if they are equal. 
       
In fact the only reason equal() exists at all is because it 
was argued (successfully) that "not compare" was being used
more frequently than just "compare".

You can replace equal() with "not compare()", so long as the return
value is not evaluated, which is uncommon. 
equal(a,b) _always_ equals abs(not compare(a,b))

Graeme

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

4. RE: compare() and equal()

Hello again,

Kat wrote:
> On 8 Apr 2001, at 23:56, Derek Parnell wrote:
> 
> 
> > 
> > Hi Kat,
> > I just did this ...
> > 
> > ? 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})
> > 
> > ...
> > and I got displayed ...
> > 
> > 0
> > 1
> > 
> > which is exactly what I'd expect. There was no error message or the 
> > like.
> 
> Well, i just changed a bunch of these:
> if equal(a,b) then
> 
> to:
> if (compare(a,b) = 0) then
> 
> because the nested sequences in the equal() line were crashing the 
> program! 
> The compare() line runs fine now.
>  
> > > Also, if equal() is true, it returns boolean true, but if
> > > compare() is true, it returns
> > > boolean false.
> > >
> > 
> > But compare() can *never* be true as it does not return a true/false
> > indicator. It isn't meant to. It just tells if parameter#1 is less than,
> > equal to, or greater than parameter#2. And this is not a boolean thing.
> 
> It returns zero or non-zero, and zero equates to false in a boolean 
> compare. 
> Equal() returns 1 (true) or 0 (false) the same way, but the true-1 in 
> equal() 
> and the true-0 in compare() feels too odd.
> 
> Kat
> 
> 

I have to agree with Kat that sometimes -1 and 1 are lumped together
as 'true' while 0 is still taken to be 'false, making the logistics
look 'boolean', even though the function doesnt return a true
boolean.

I have to agree with Derek though, in that the two lines of
code both function properly, so i would think Kat is typing
something incorrectly.

Kat, would you like to cut and paste your exact code here,
instead of typing it out manually? Perhaps the error will
show up.  You can also try swapping the two lines of code
and see if that shifts the error to the 'compare' line.

Euphoria's interpreter sometimes doesnt report an error
untill it can fully resolve a block of code.

Good luck with it.
--Al

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

5. RE: compare() and equal()

On 10 Apr 2001, at 4:43, Al Getz wrote:

> 
> Kat wrote:
> > On 8 Apr 2001, at 23:56, Derek Parnell wrote:
> > 
> > 
> > > 
> > > Hi Kat,
> > > I just did this ...
> > > 
> > > ? 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})
> > > 
> > > ...
> > > and I got displayed ...
> > > 
> > > 0
> > > 1
> > > 
> > > which is exactly what I'd expect. There was no error message or the 
> > > like.
> > 
> > Well, i just changed a bunch of these:
> > if equal(a,b) then
> > 
> > to:
> > if (compare(a,b) = 0) then
> > 
> > because the nested sequences in the equal() line were crashing the 
> > program! 
> > The compare() line runs fine now.
> >  
> > > > Also, if equal() is true, it returns boolean true, but if
> > > > compare() is true, it returns
> > > > boolean false.
> > > >
> > > 
> > > But compare() can *never* be true as it does not return a true/false
> > > indicator. It isn't meant to. It just tells if parameter#1 is less than,
> > > equal to, or greater than parameter#2. And this is not a boolean thing.
> > 
> > It returns zero or non-zero, and zero equates to false in a boolean 
> > compare. 
> > Equal() returns 1 (true) or 0 (false) the same way, but the true-1 in 
> > equal() 
> > and the true-0 in compare() feels too odd.
> > 
> > Kat
> > 
> > 
> 
<snip>

--if equal(left,right)
            if (compare(left,right) = 0) -- 0 = equal !!
		  then result &= sprintf("%s", {right})
		  else result &= sprintf("[%s,%s]", {left,right} )
                end if

that is copy/pasted, which messed up the indents. The top line errors out, 
the bottom line runs fine.

ACK ok, something odd going on... i just commented out the compare() to 
use the equal() and get the ex.err to copy paste here too, and it ran, 
crashing at the else line. But i swear to you, if it had not been crashing, 
reporting the error on the equal() line, i sure wouldn't have re-written it to
use
compare()! Btw, that's code undergoing revisions, not working code in 
anything.
 
> Euphoria's interpreter sometimes doesnt report an error
> untill it can fully resolve a block of code.

erg.

Kat

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

6. RE: compare() and equal()

Hi Kat,
ain't programming fun. Mind you, I doubt if you would have had problems if
Euphoria allowed you to write ...

   sequence left, right
   . . .
   if left = right
   then result &= sprintf("%s", {right})
   else result &= sprintf("[%s,%s]", {left,right} )
   end if

-----------
cheers,
Derek Parnell

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

7. RE: compare() and equal()

> -----Original Message-----
> From: Kat [mailto:gertie at PELL.NET]
 
> --if equal(left,right)
>             if (compare(left,right) = 0) -- 0 = equal !!
> 		  then result &= sprintf("%s", {right})
> 		  else result &= sprintf("[%s,%s]", {left,right} )
>                 end if

I think I see what the problem is.  Earlier, you said that the error was:
"it faults out with an error about a sequence being in there."  I think this
was really coming from sprintf rather than equal/compare, because sprintf
will choke if right or left have a nested sequence (ie, they're not really
strings).

Matt Lewis

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

Search



Quick Links

User menu

Not signed in.

Misc Menu