1. Re: [If/then and sequences...]
- Posted by Derek Parnell <derekp at solace.com.au> Aug 30, 2000
- 397 views
Hi Irv, thanks for pointing this out. In a lot of programming languages, the operators '<', '>' and '=' always return a boolean result - that is either TRUE or FALSE. What you've demonstated is that in Euphoria, these operators return a boolean when both operands are atoms, and return a sequence when either operand is a sequence (unless the operand is used in an IF statement, in which it is illegal). And that compare() function always returns an atom (and equal() function always returns a boolean), regardless of operands data type. In my mind that is inconsistent and also not simple. Its just that from my point of view, it would have been more intuitive, and simpler, to reverse this arrangement of Robert's. That is, have the '<', '>', and '=' operators always return a boolean (and allow their use in IFs), and have the compare() function return a sequence. This probably would have made the equal() function redunant. Of course its WAY too late to introduce this sort of change to the language, and I'm not advocating that. I'm just wondering why Robert decided to arrange the language the way he did. To show it again... Current: Operation Operands Allowed in IF Result ------------------------------------------------------------------- =/>/< atoms yes boolean =/>/< sequences no sequence =/>/< mixed no sequence compare() atoms yes atom compare() sequences yes atom compare() mixed yes atom equal() atoms yes boolean equal() sequences yes boolean equal() mixed yes boolean if atom yes boolean if sequence no n/a Alternative: Operation Operands Allowed in IF Result ------------------------------------------------------------------- =/>/< atoms yes boolean =/>/< sequences yes boolean =/>/< mixed yes boolean compare() atoms no sequence compare() sequences no sequence compare() mixed no sequence equal() atoms yes boolean equal() sequences yes boolean equal() mixed yes boolean if atom yes boolean if sequence no n/a ----- cheers, Derek Parnell >-----Original Message----- >From: Derek Parnell [mailto:dparnell at bigpond.net.au] >Sent: Wednesday, August 30, 2000 9:30 AM >To: derekp at solace.com.au >Subject: Re: [If/then and sequences...] > > >On Tue, 29 Aug 2000, you wrote: >> Agreed Matt. I'll never support a greater_than/less_than >function. In fact, >> I can't understand the rationale behind compare() and equal() >either. To me, >> it seems a lot more intuitive just to use the '=', '<', '>' symbols with >> sequences. I can't understand Robert's idea that using these symbols with >> sequences is a bad thing. >> >> So what's the big deal with ... >> >> sequence A,B >> >> if A = B then .... > >Run this little program, look at the output, and see why we might >want = to do >what it does... > >sequence a,b >a = {"Mary","Joe","Tim","Sue","Arnold"} >b ={"Mary","Moe","Tom","Sue","Arnold"} > >? equal(a,b) >? compare(a,b) >? a = b > >-- >--Regards, >--Irv >