Re: match() (not short, he he)
- Posted by Derek Parnell <ddparnell at bigpond.com> May 27, 2003
- 370 views
----- Original Message ----- From: <gertie at visionsix.com> To: "EUforum" <EUforum at topica.com> Subject: RE: match() (not short, he he) [snip] > > > i=match("b","abc"}}) -- ret 2 > > I say no. The b in "abc" looks like an atom to me, and you told match to look > for a "b", which is a sequence. Well, actually that turns out not to be the case. You see, when one writes 'match("b", someseq)' they are really asking for the location of the first SLICE of someseq that is {'b'} (aka "b"). Now if someseq is "abc" the the first slice of someseq that is the same as "b" is someseq[2..2] and its location is at position #2. > > i=match("b",{"a","b","c"}) --ret 2 > > Yes. Hmmm. No, actually. Using the same reasoning I gave above, if someseq is {"a","b","c"} which is the same as {{'a'},{'b'},{'c'}} then we can see that there is no slice of this that is the same value as {'b'}. It might look like the second element matches but someseq[2..2] is {{'b'}} and not {'b'}. True the second element is {'b'} but match() is looking for slices, not elements. > > i=match("b",{{"a","b","c"}}) --ret 2 > > i=match("b",{{{"a","b","c"}}}) --ret 2 > > No, and no. You are correct here, but probably not for the right reasons. Doesn't matter. > > You really have to stick your result into some code > > to find out what really happens next, once you > > think you have determined a better return result. > > Doesn't matter what i code, Rob isn't going to put it into the official Euphoria, > is he? > Well that seems to be true with nearly all previous suggestions. However, one of my bosses used to say "Trends are not Destiny". I guess what we are really saying is 1) that it would be nice if Euphoria would return a value, say 0, for zero-length LHS parameters in match() rather than crashing. 2) If the LHS parameter of match() is an atom, treat it as if it was a single item sequence. Neither of these would break existing code. ---------------- cheers, Derek Parnell