Re: Sequence comparison

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

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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu