1. RE: match()

Christian.CUVIER at agriculture.gouv.fr wrote:
> 
> 
> 	Since match() is meant to look into a sequence for another sequence, it 
> 
> looks for "something" in "something", as Juergen said.
> 	So calling match(.,.) with one or both arguments empty is an invalid 
> condition. Returning -1 (just like routine_id on an unknown routine 
> name) seems much more flexible and adequate than throwing out an error, 
> so I'd push for this change.
> 
> 	CChris
> 
> 
Hello there,

That's a very logical way of looking at it, i forgot about
routine_id() and it's silent failure mode.

You cant, however, allow match to return -1 because it would
break far too much existing code.  On the other hand, returning
a zero when one or both args are null wouldnt break any code.

This means 

match("",s)
match(s,"")
match("","")

all should return zero, without regard for what is (or isnt)
contained within the sequence s.


Side note:
The only reason routine_id returns a -1 and not a zero is because 
zero is an allowed routine id.

Take care,
Al

new topic     » topic index » view message » categorize

2. RE: match()

Juergen Luethje wrote:
> 
> 
> Hi Al, you wrote:
> 
> <snip>
> 
> > On the other hand, returning
> > a zero when one or both args are null wouldnt break any code.
> >
> > This means
> >
> > match("",s)
> > match(s,"")
> > match("","")
> >
> > all should return zero, without regard for what is (or isnt)
> > contained within the sequence s.
> 
> <snip>
> 
> match("","") IMHO should raise an error, or return -1 (or another flag
> to indicate an illegal operation), or return 1 (*not 0*).
> 
> Since match("ab","ab") returns 1, because both strings are identical,
> match() for any other two strings x and y, where  equal(x,y) = 1,
> should never return 0. IMHO.
> 
> Best regards,
>    Juergen
> 
> -- 
>  /"\  ASCII ribbon campain  |    |\      _,,,---,,_
>  \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
>   X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
>  / \  and unneeded MIME     |  '---''(_/--'  `-'\_)
> 

hi Juergen, i like your little pic there smile

So far i think i've agreed with you on most issues, but
returning 1 from match with two null sequences isnt one
of them that i can agree on.

In real life, the two characters that make up the null ""
appear as simply:

""

so if you happen so spot two more, like this:

""

it is very logical to say that you have found the EXACT
same thing in the second instance as the first (above).
To enumerate this, we could say we have found exactly one
of these 'things' and so it would make sense to assign the
number 1 to this circumstance.

On the computer, however, it's a very different world.
First off, we our operating within the context of a
programming language, which has to meet certain criteria
which is different then that in the most basic, real life
situtation.
For one thing, we have to be consistant in whatever we do,
or the language will have a lot of anomalies and it will
be hard to use.  Granted, Euphoria has some of these already,
that's why we ended up discussing this issue, but the idea
is to REDUCE the number of anomalies over time in order to
perfect the language.
How do we accomplish this?
The answer lies in discovering how the individual functions 
work as a whole, and determining which ones dont quite fit
in as well.

In this case, we are talking about the function match, which
has to work with two sequences, and has to return a value that
is commensurate with the code that will follow, as well as with
other functions that use sequences.

The other interesting thing about match though, is that it
is basically searching for something, within a sequence.
If it finds something, it returns a number from 1 to max integer.
If it doesnt find anything, it returns a zero.

Let me repeat that last line one more time:

"If it doesnt find anything, it returns a zero."


Now in the real world, when we find
""
we have indeed found something, but in the Euphoria language
when we find
""
we have not found anything
(unless it is nested inside of another sequence such as {""} ).

The evidence for this lies in looking at other functions
that use sequences.

sequence s
s="abc"

here we have a sequence "abc".

We add that which we suspect is something, namely, "d"

s=s&"d"

We end up with a new sequence, s, which NOW equals

"abcd"

Note that 

"abcd"

is not the same as the original sequence,

"abc"

and so we can say, with absolute certainty, that

"d"

is SOMETHING, because it physically changed "abc".

This means 

match("d","abcd")

should return a number, not zero, because zero says we havent found
anything.

Now, lets do the same experiment with "".......

start again with s

s="abc"

now lets add that which we suspect is SOMETHING, namely, ""

s=s&""

Now we end up with

"abc"

which is the same sequence as we started with, s="abc", and therefore

""

is clearly not SOMETHING.
It is in fact nothing, at least in a Euphoria one level sequence.


So you see, although we have no trouble finding "" in the real world,
perhaps in a page of text, we do have trouble finding it within a 
first level sequence that already exists in the Euphoria language.


Now back to the match function...

We found out that "" is not SOMETHING in Euphoria, it is NOTHING,
so we cant ever hope to find it within a one level sequence.
This means

match("","")

is the same as

match("",s)

because we wont ever find anything if we are looking for nothing.

Side note:
If we are looking though a multi level sequence
such as {"abc","",{""}}
match has to return a zero because of a different reason,
namely, because the search level is different.


If you want to assume that if you are looking though nothing in hopes
of finding nothing and you do indeed find nothing (because after all,
if you find nothing havent you actually found it?), that you have
actually found something because you have found nothing, then you can
see that this still defaults to having found NOTHING!
The reason for this is that when you look for nothing,
it's just an idea, not a concrete object.

Not only that, in real life 
you cant actually even get as far as to look for nothing, because then
you could say you were actually looking for something, which you werent.
On the computer however, this isnt true, because we can actually look
for nothing because although nothing really doesnt exist, it still has
a representation.


Also, as i said before, returning  0 from

match("",s)

where s is ANY sequence, doesnt break any existing code,
whereas every other idea i've heard so far does, no matter
how good (or bad) it sounded.

One advantage is that you can use the line
   while match(...)
whereas right now you cant, unless you can also make sure
the first sequence will never be null.



I've understood your arguements, now try to understand mine.


Take care for now,
Al

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

Search



Quick Links

User menu

Not signed in.

Misc Menu