Re: Conditional handling (was Re: Reading a file into a "sequence")

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

Jason Gade wrote:
> 
> Pete Lomax wrote:
> > >Jason Gade wrote:
> > >[snip]
> > >> Be equivalent to equal(s1, s2) when found in a conditional (if, when)
> > >> Have the result sequence (1, 0, 1, 1) be reduced to an atom that is TRUE
> > >> if and only
> > >> if all of its elements are true, again only in a conditional statement
> > >> (if, when).
> > >> 
> > >> Personally I prefer the second example.
> > Although this may be a moot point, I have to disagree completely with
> > the selection of the second as "preferred". I hope you'll forgive me
> > for being a bit blunt about it.
> > 
> > There is no point in generating a sequence if you plan to immediately
> > "reduce" it to a boolean.
> > 
> > It would be much faster just to create the boolean in the first place.
> > (Which of course I firmly believe it should do)
> > 
> > While the above (second) idea might be workable for equal, it would
> > not be for other relational operators. For example:
> > 
> > "if {1,2,3} >= {1,2,2} then" creates {1,1,0} "reduced" to FALSE.
> > 
> > "if {1,2,3} >= {1,1,2} then" creates {1,1,0}, "reduced" to TRUE.
> > 
> > Unless, of course, you have a magic routine which converts {1,1,0}
> > into true in some cases and false in others.
> > 
> > As for flexibility, the concept of arbitrarily interpreting a sequence
> > as either true or false is just nonsense.
> > 
> > It should produce an error, as it currently does.
> > 
> > What the language should not do is create a sequence in situations
> > where the only possible outcome of so doing is a crash.
> > 
> > Regards,
> > Pete
> 
> Good point.  So do you think that comparison operators should work like equal
> and compare
> in if and when statements, or should it remain as-is?

Not as-is. When comparision operators appear in IF or WHILE statements, 
they should result in a boolean value (true/false) and never a sequence.
I think that RDS chose the wrong operation to perform in those contexts.

Further more, if RDS changed Euphoria to behave as if a compare() had
been coded, it would *not* break any existing code, because any code 
with this in it now is already broken. Instead, it could cause people
to write programs that looked and felt right.

The sematics of the IF wouldn't change either, as 'IF <sequence> THEN'
is still an error, as it should be. The change is simply that 
'IF <sequence> <relop> <object> THEN' would be automatically produced as 
'IF COMPARE(<sequence>,<object>) <relop> 0 THEN' 

I am not saying the the sequence operation is never to be used, only
it shouldn't be used in these contexts.


-- 
Derek Parnell
Melbourne, Australia

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

Search



Quick Links

User menu

Not signed in.

Misc Menu