Re: Error messages

new topic     » goto parent     » topic index » view thread      » older message » newer message

On  2 Oct 97 , Carl R. White wrote:

> > Hello again -
> >
> > These questions are for Rob Craig, but anyone who knows the answers can
> > speak up.
> >
> > 1.      The reference manual says a sequence is just like any number and can
> > be treated as such.  But I sometimes get an error message:  "True/false
> > conditions must be an atom."  This implies that the line:
> >
> >         if {seq1} = {seq2} then (do something)
> >
> > is illegal, and should be changed to something like:
> >
> >         if {seq1[1]} = {seq2[1]} and {seq1[2]} = {seq2[2]} and ...
> >
> > That's a real can of worms.  What's wrong here?
>
> I used to make this mistake all the time, having bee "born and bred" on
> BASIC. I've found that the common workaraound is to use:
>
>         if compare(seq1, seq2) = 0 then
>             do_something()
>         end if

You must use 'compare', because seq1 = seq2 will evaluate to a
SEQUENCE of boolean values (true/false, or 1/0)... example:

seq1={1,2,3,4,5}
seq2={4,2,3,6,5}
print(1,seq1=seq2)

Will print {0,1,1,0,1}, because Euphoria test item 1 of seq1 with
item 1 of seq2 and then stores as item 1 of resulting sequence the
boolean value, this is repeated for every element in the sequence.

The if..then/while..do structures require a BOOLEAN (true/false)
condition to determine what to do, but we've got a sequence here...
that's why we got an error.

As you can see, Carl's solution is right... but it's good to know why
you can't do it the other way ;)

Regards,
  Daniel Berstein
  danielberstein at usa.net
  http://www.geocities.com/SiliconValley/Heights/9316

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu