Re: match() (not short, he he)
- Posted by gertie at visionsix.com May 26, 2003
- 341 views
On 26 May 2003, at 15:56, jbrown1050 at hotpop.com wrote: > > > On Mon, May 26, 2003 at 02:41:47PM -0500, gertie at visionsix.com wrote: > > > > > > On 26 May 2003, at 15:04, jbrown1050 at hotpop.com wrote: > > > <snip> > > > what would match({"at"}, {"k","","at"}) return? > > > > 0 > > That is wrong. If match("at", "kat") returns 2, then > match({"at"}, {"k","","at"}) should return 3. but match("at",{"k","at"}) would return 2, right? so why would nesting the "at" even deeper match({"at"},{"k","at"}) also return 2? > What you appear to be proposing is > turning match() into find(). It has often confused me that there are 2 functions that do almost the same thing: match() and find(). > <snip> > > > To avoid retyping, i'll add these constants: > > > > > > constant x = {"k","","at"}, y = "" > > > > > > y is an element of x, but it is not a subsequence of it. I think, that > > > using > > > match() to find elements (even if the element itself is a sequence) is a > > > bad > > > idea (but not so bad that it should be a run-time error). > > > > > > I think, we should be universal ... if match(y, x) returns 2, then > > > match('a', "kat") should also return 2. > > > > Correct! Now you've got it! > > And I think that being universal in allowing atoms is incorrect. That makes > certain sequence matching extremely complex, to the point of confusion. But in "kat", each character is an atom. In {"kat"}, "kat" is a sequence inside another sequence { }. For the 'k' to be a sequence, it should read as {"k","a","t"}. In {'k',"at"}, 'k' is an atom, and "at" is a sequence. Unless you specify 'k' is a sequence, as in {"k","at"}. In {"k","at"}, 'k' is not found except as the first element of the first subsequence. So if i specify match('k',{"k","at"}), 0 should be returned. In match("k",{"k","at"}), 1 should be returned. And if that is true, then un-nesting the "k" and "at" from their own subsequences, to form match('k',"kat"), should return 1, since "kat" should equal {'k','a','t'}. Kat