1. Sequence comparison
- Posted by Michael Nelson <mike-nelson-ODAAT at WORLDNET.ATT.NET> Apr 25, 2000
- 405 views
I almost never use compare() directly. I use equal(0 and the following very simple comparisons of my own (might run a bit faster if incorporated into EU): global function less(object a,object b) return compare(a,b) = -1 end function global function greater(object a,object b) return compare(a,b) = 1 end function global function between(object a,object b,object c) return compare(a,b) > -1 and compare(a,c) < 1 end function greater-than-or-equal-to can be expressed as not less(), etc. -- Mike Nelson
2. Re: Sequence comparison
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> Apr 25, 2000
- 396 views
Hello Michael Nelson, These look useful but I had one question about between() >global function less(object a,object b) > return compare(a,b) = -1 >end function > >global function greater(object a,object b) > return compare(a,b) = 1 >end function > >global function between(object a,object b,object c) > return compare(a,b) > -1 and compare(a,c) < 1 >end function what if b > c? Your function wouldn't work would it? How about this: global function between(object a,object b,object c) return (compare(a,b) > -1 and compare(a,c) < 1) or (compare(a,b) < 1 and compare(a,c) > -1) end function just a thought, Lewis Townsend ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
3. Re: Sequence comparison
- Posted by No Solution <solutionnone at HOTMAIL.COM> Apr 25, 2000
- 385 views
>I almost never use compare() directly. I use equal(0 and the following >very >simple comparisons of my own (might run a bit faster if incorporated into >EU): > >global function less(object a,object b) > return compare(a,b) = -1 >end function > >global function greater(object a,object b) > return compare(a,b) = 1 >end function > >global function between(object a,object b,object c) > return compare(a,b) > -1 and compare(a,c) < 1 >end function > >greater-than-or-equal-to can be expressed as not less(), etc. > >-- Mike Nelson Yes i am aware of this option, but that is still using functions, i am just wondering if Rob ever wanted to implement an operator for sequence comparison. like this: sequence s1,s2 s1 = "ian" s2 = "ian" if s1 $= s2 then printf(1,"s1 = s2\n",{s1,s2}) else printf(1,"s1 != s2\n", {s1,s2}) end if ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
4. Re: Sequence comparison
- Posted by Robert Craig <rds at ATTCANADA.NET> Apr 25, 2000
- 375 views
- Last edited Apr 26, 2000
No Solution writes: > Yes i am aware of this option, but that is still using functions, > i am just wondering if Rob ever wanted to implement an > operator for sequence comparison. > like this: > sequence s1,s2 > s1 = "ian" > s2 = "ian" > if s1 $= s2 then ... I don't think there is much difference in readability between: s1 $= s2 and equal(s1, s2) and functions, such as equal(), that are built in to the interpreter carry no extra overhead when compared with operators, so speed is not an issue. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
5. Re: Sequence comparison
- Posted by Michael Nelson <MichaelANelson at WORLDNET.ATT.NET> Apr 26, 2000
- 365 views
Lewis Townsend writes: <snip> >I had one question about between() > > > >global function between(object a,object b,object c) > > return compare(a,b) > -1 and compare(a,c) < 1 > >end function > > what if b > c? Your function wouldn't work would it? > How about this: > > global function between(object a,object b,object c) > return (compare(a,b) > -1 and compare(a,c) < 1) > or > (compare(a,b) < 1 and compare(a,c) > -1) > end function Lewis, you are quite correct--if we want between(5,1,10) and between(5,10,1) to both return 1 we must use your code. This makes the minimum and maximum interchangeable, which may be exactly what is needed. I deliberately designed between so that if min>max between always returns 0--this is the behavior needed for some algorithms and for subscripting/slicing--for example if s is a sequence of length(10): between(5,3,7) returns 1 indicating element 5 is in the slice, but between(5,7,3) returns 0 indicating element 5 is not in the (invalid) slice. Perhaps both should be available under different names. -- Mike Nelson
6. Re: Sequence comparison
- Posted by No Solution <solutionnone at HOTMAIL.COM> Apr 26, 2000
- 387 views
> >I don't think there is much difference in readability between: > s1 $= s2 >and > equal(s1, s2) >and functions, such as equal(), that are built in to >the interpreter carry no extra overhead when compared >with operators, so speed is not an issue. > that's true as well.. but it's just a preference of mine, and maybe others, to use operators where possible. Ian Smith ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com