1. Re[2]: match()
This reply covers all of the other replies... thanks.
But I think match is a function such that:
if match(s1, s2) returns ret, then
s2[ret..ret+length(s1)-1] equals s1
Example:
ret = match("AB", "ABC") -- ret = 1
"ABC"[1..1+2-1] = "AB" -- OK
ret = match("", "ABC") -- ret = 1 (example)
"ABC"[1..1+0-1] = "" -- OK
-- because "ABC"[1..0] equals ""
I think "" matches position 1,2,3,...,length(s2) *and not 0*,
and because "where the (first) matching slice begins [DOC]", it should
return 1.
But it can cause undetected bugs. Or with current match routine it can
terminate the program unexpectedly. How about changing the match()
run-time error into a warning?
j> Why not just return -1 then? Seems silly this should be a run-time error...
j> jbrown
j> On Mon, May 26, 2003 at 10:07:06AM +0200, Juergen Luethje wrote:
>>
>>
>> Hello Aku, you wrote:
>>
>> > match("", "something") shows an error
>> > first argument of match() must be a non-empty sequence
>> >
>> > I think it should return 1,
>>
>> The equivalent function to match() in BASIC is instr(), and that's
>> actually the way instr() works.
>> My experience after about 10 years programming in BASIC is, that this
>> often causes problems. Especially it can cause bugs, that are very hard
>> to find by beginners.
>>
>> > because "" is a substring of "something",
>> > and is located in any position.
>>
>> This is a philosophical question, isn't it?
>>
>> > So I don't have to check if the first argument is "", don't call
>> > match().
>> >
>> > How do you think?
>>
>> Best regards,
>> Juergen
>>
>> --
>> /"\ ASCII ribbon campain | "Everything should be made as simple
>> \ / against HTML in | as possible, but not simpler."
>> X e-mail and news, |
>> / \ and unneeded MIME | http://www.sfheart.com/einstein.html
>>
>>
>> TOPICA - Start your own email discussion group. FREE!
>>