#78902 - 2002-06-06 05:11 PM
Re: Instr() Behaviour
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Original thread here.
{EDIT} Oops - fixed link. {/EDIT} [ 10 June 2002, 10:03: Message edited by: Richard Howarth ]
|
Top
|
|
|
|
#78908 - 2002-06-10 09:59 AM
Re: Instr() Behaviour
|
Bxn
Getting the hang of it
Registered: 2002-06-05
Posts: 63
Loc: Alpha Centauri
|
Very Disapointed about these views, Lonkero ... First of all my poor english probably prevented me to fully understand the very substance of your first post ... (20020608 04:35), but I guess it's largely discussing about the duty of a programmer to check the values of variables used in order to prevent a lot of confusing things. If it is so, I of course agree with that ... Be sure I check the numeric variable $X before evaluatin' 1/$X ! Concerning the second post, I think, you certainly noticed that in my first post, I suggested too that "nothing was in everything". Well, but I don't agree with your statement "with nothing everychar matches". the term "matches" is to vague to be USEFUL in a programming language (Thanx to Richard Howarth to have remind me this premacy of 'useful' coding against 'beauty of mathematical concepts' ! ). I realized that if I accept an Empty String matches a "A", tomorrow, one programming language developper will furbish me with the super tricky function SuperTrickyGraphicalInstr(), which will return 1 when I evaluate SuperTrickyGraphicalInstr(";","."), just simply it found a dot in ";". Unless very much documented, a fine and consistent function should only evaluate Strict Identity, not 'belonging'. You also state "it start counting from 1", unless you are the developper of KiXtart, that's only one point of view. I personnally have to suggest would someone want to reflect the "theorical fact" that empty is in everything, in my example with string "ABCD", it should check the empty space before the A and shout : "Match !" and return 0 (suggested also and again by Richard Howarth).
In terms of consistency, reliability and efficiency, you didn't convince me, but did you ever tried ?
Nevertheless, this debate could be opened for other programming languages (or self proclammed Prog. Lang. !) : I have tried equivalent functions with Turbo Pascal 7 [Pos() function] and MS Excel [localized Cherche() function] ... With my example, the first returns 0, the second returns 1 ...
|
Top
|
|
|
|
#78911 - 2002-06-10 10:52 PM
Re: Instr() Behaviour
|
Bxn
Getting the hang of it
Registered: 2002-06-05
Posts: 63
Loc: Alpha Centauri
|
Dear Jack,
That's in substance what I said.
But you see it obviously lead to some debate among developpers.
Nevertheless, if you agree our PoV (or Howard's) you can't say the function is really consistent as provided.
You said :
"Logically if you search for nothing you will find what you are searching for."
Uh oh ! That was the meanin' of my first post : "Nothing is in Everything". But we are programmers, we don't "search for nothing", we search for the "null string" and as far as I know in a programming language the Null String is not 'nothing', it's not the 'no code' character.
As a programmer, I don't expect from a function to answer : "Oh you lazy boy, you're lookin' for nothin' so here's my answer : you win, and first try !" where first try would lead me to "A" or "Z" ...
"Furthermore since you found something it must be somewhere. Logically it was in the first place you looked. Logically I think the function is consistent."
I already have heard this (Hey Lonkero !) ... But why should the first place we look, be the number "1" ? Especially concerning the Null String, the first place we have to look, is before the first char., where there's nothing as we all agree ... Returnin' "1" is not consistent. "1" is the position of the "A", and even if we all agree the element "nothing" is in every set, I've never been told that the element "nothing" was in all element of the set ! That's, I think another common confusion.
"Consider the point if you search for a null string in a null string" Yes, there is strict identity between these values, but what's the lenghth of the null string ? Would it really have sense to return "1" where length is "0" ? So, I would like a returned value of -2.
"But consistency is not everything," sure, that's why I like Neural Networks so much.
"I think the thrust of Howard's comments is that in this case usefulness might be a better criteria than logic. I tend to agree with Howard"
So Do I, But His Rate Is Already At Max.
|
Top
|
|
|
|
#78914 - 2002-06-11 02:47 PM
Re: Instr() Behaviour
|
Bxn
Getting the hang of it
Registered: 2002-06-05
Posts: 63
Loc: Alpha Centauri
|
Lonkero, You're right, I certainly go too far in this case ! And I think you're right too when noticing it's language dependent !
And Finally, I'm glad to see your PoV more accurately ...
|
Top
|
|
|
|
#78915 - 2002-06-11 03:26 PM
Re: Instr() Behaviour
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Lonkero, quote: is 0 length string same as if it contains null? NOT.
Well, to be pedantic yes it is. The null character Chr(0) terminates a string. Therefore a string is actually all the character you can see, plus a Chr(0) at the end that you can't.
The string "Hi!" is actually four characters long - 'H' 'i' '!' '\0'
The empty string "" is 1 character long - '\0'
This is the core reason why you cannot easily manipulate binary data as strings.
|
Top
|
|
|
|
#78918 - 2002-06-11 08:59 PM
Re: Instr() Behaviour
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
This is a GREAT discussion!
I find myself more and more in agreement with the idea that:
SUBSTR($X,"") should always return 0.
As was mentioned before, the value returned is an index of the first instance of the 2nd string passed to the function. Even if using set theory causes us to say that the null set is in anything, the value indexed as 1 can never be equal to an empty string.
Brian
|
Top
|
|
|
|
#78920 - 2002-06-11 09:05 PM
Re: Instr() Behaviour
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
How is zero incorrect? If the 2nd string (not empty) is not in the 1st string, then there is no index, either, so zero is returned. This would be exactly the same situation. Are you saying that if a string doesn't exist in the other string, we should assign that a negative value as well?
Brian
|
Top
|
|
|
|
Moderator: ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 2145 anonymous users online.
|
|
|