Re: more match() problems
- Posted by Derek Parnell <ddparnell at bigpond.com> May 28, 2003
- 456 views
On Wed, 28 May 2003 07:43:20 +0000, Al Getz <Xaxo at aol.com> wrote: > > > Hello again, > > Looking closer at the match() function, > i find that it doesnt really work very well > unless you are only using it on one level sequences (like {1,2,3} or > "abc"). > > Untill this point, i dont think i ever used it > for anything else, but since we were looking at it > anyway i thought i would mention this. > > match({2,3},{1,2,3}) > > returns the number 2, because the 'slice' was found > in the second sequence. Works fine. > > Now, > > match({{1,2,3}},{{1,2,3}}) > > returns the number 1, because again the 'slice' (although this time > deeper) was found in > the second sequence. Works fine. > > Nowwwwwwwww... > > what does > > match({{2,3}},{{1,2,3}}) > > return? (same example with the 1 missing in first arg) > > If you said the number 2, you are correct, because > the 'slice' could be found in the second sequence > at the required level, right??? > > Well, guess again! > The Eu match command returns a big fat zero! > > Yes, that's right, > > i=match({{1,2,3}},{{1,2,3}}) -- rets 1 > but > i=match({{2,3}},{{1,2,3}}) -- rets 0 > > > Care to try to figure that out? Sure. Let's look at all the possible slices of {{1,2,3}}, shall we. s = {{1,2,3}} Length of s is 1, right? So then there is only one slice, namely s[1..1] and its value is {{1,2,3}}. Now the LHS side of your match was {{2,3}}. Can you locate this value in any of the slices (all one of them) of s? > I guess i went too far in assuming there was a method > to the madness. > > Anomaly number 97316 and counting... Not an anomaly at all. I keep saying this but it doesn't seem to be making it across the language barrier... match() LOOKS FOR SLICES - ALWAYS. find() LOOKS FOR ELEMENTS - ALWAYS. -- cheers, Derek Parnell