match() != find()

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

On Mon, May 26, 2003 at 05:25:45PM -0500, gertie at visionsix.com wrote:
> > > > 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?

No. That would be zero.

match("at",{"k","at"}) is the same as match({'a', 't'},{"k","at"})

find("at",{"k","at"}), of course, returns 2.

> 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().

They don't. They do different things. match() is designed for strings
("ab" in "abc") and find() is designed for elements ('a' in "abc", or "a" in
{"a", "b", "c"})

<snip>
> > 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'}.

You realize, you just described find() perfectly.

What match() does, is find sequence matches on the same level. I.e.

"kat"

level 1 -> "kat"

level 2 -> 'k'

{"kat", "bean"}

level 1 -> {"kat", "bean"}

level 2 -> "been"

level 3 -> 'e'

match("at", "kat") will return something, because "at" and "kat" are on the
same level ... match("at", {"k", "at"}) will fail because they are on different
levels.

find(), otoh, works on a different level. The second parameter has to be
one level higher than the first parameter. So find("at", {"k", "at"}) will
return 2, since {"k", "at"} is a level above "at".

I'm not sure if that explaination was clear.

jbrown

> 
> Kat
> 

-- 
 /"\  ASCII ribbon              | http://www.geocities.com/jbrown1050/
 \ /  campain against           | Linux User:190064
  X   HTML in e-mail and        | Linux Machine:84163
 /*\  news, and unneeded MIME   |

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

Search



Quick Links

User menu

Not signed in.

Misc Menu