1. more match() problems

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?

I guess i went too far in assuming there was a method
to the madness.

Anomaly number 97316 and counting...

 smile

Take care,
Al

new topic     » topic index » view message » categorize

2. Re: more match() problems

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: more match() problems

Derek Parnell wrote:

<snip>
>   match() LOOKS FOR SLICES - ALWAYS.
>   find() LOOKS FOR ELEMENTS - ALWAYS.
</snip>

This is entirely correct and is as it should be. I would further emphasize
that find() and match() only work at the top level.

Since match() always looks for slices, an atom as the first parameter is and
should be an error.  An empty sequence as the first parameter is also an
error--a return of 0 is preferable, as it would eliminate some special case
checking from code using match().

-- Mike Nelson

new topic     » goto parent     » topic index » view message » categorize

4. Re: more match() problems

On Wed, May 28, 2003 at 02:47:51PM -0500, gertie at visionsix.com wrote:
<snip>
> I always do something like this:
> 
> if atom(x) 
>   then z = match({x},y)
>   else z = match(x,y)
> end if
> 
> or 
> 
> if sequence(x) 
>   then z = match(x,y)
>   else exit -- cannot use a goto eoroutine here!
> end if
> 
> If i don't, sure as heck x will be "" eventually and the app will crash.
> Testing
> for equal(x,"") or (length(x) = 0 ) repeatedly, over and over, ad nauseum 
> helps(?) too.
> 

Why not:

function mx(object x, sequence s)
	return match(x, s)
end function
global function match(object x, sequence s)
	if atom(x) then
		x = {x}
	end if
	if length(x) = 0 then
		return 0
	end if
	return mx(x, s)
end function

That would get you almost exactly what you want, at the price of including one
more file into your program(s). No need to type repeatedly like that anymore ;]

> Kat
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
> 

-- 
 /"\  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     » goto parent     » topic index » view message » categorize

5. Re: more match() problems

On 28 May 2003, at 20:11, jbrown1050 at hotpop.com wrote:

> 
> 
> On Wed, May 28, 2003 at 02:47:51PM -0500, gertie at visionsix.com wrote:
> <snip>
> > I always do something like this:
> > 
> > if atom(x) 
> >   then z = match({x},y)
> >   else z = match(x,y)
> > end if
> > 
> > or 
> > 
> > if sequence(x) 
> >   then z = match(x,y)
> >   else exit -- cannot use a goto eoroutine here!
> > end if
> > 
> > If i don't, sure as heck x will be "" eventually and the app will crash.
> > Testing for equal(x,"") or (length(x) = 0 ) repeatedly, over and over, ad
> > nauseum helps(?) too.
> > 
> 
> Why not:
> 
> function mx(object x, sequence s)
>  return match(x, s)
> end function
> global function match(object x, sequence s)
>  if atom(x) then
>   x = {x}
>  end if
>  if length(x) = 0 then
>   return 0
>  end if
>  return mx(x, s)
> end function
> 
> That would get you almost exactly what you want, at the price of including one
> more file into your program(s). No need to type repeatedly like that anymore
> ;]

Nice, but there is overhead in function calls, and you make two of them.

Kat

new topic     » goto parent     » topic index » view message » categorize

6. Re: more match() problems

On Wed, May 28, 2003 at 08:43:21PM -0500, gertie at visionsix.com wrote:
<snip>
> Nice, but there is overhead in function calls, and you make two of them.
> 
> Kat
> 

That is true, but if that were the most important thing we'd all be programming
in assembler (or perhaps even in raw machine code!).

jbrown

-- 
 /"\  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     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu