Zulip Chat Archive

Stream: lean4

Topic: should we redefine `String.splitOnAux`?


Bulhwi Cha (Jun 13 2023 at 15:00):

I think there are redundant parts of the definitions of String.splitOnAux and String.splitOn. See my commit. The redefined splitOnAux is not equal to the previous one, but this is what I intended. I guess the new splitOn equals the old one.

Redefined functions

Mauricio Collares (Jun 13 2023 at 15:08):

Did you try testing chabulhwi.splitOn ""?

Mauricio Collares (Jun 13 2023 at 15:15):

I think the other change looks correct, though, because assuming sep is not empty one can prove that sep.atEnd j is always false at the start of the function.

Bulhwi Cha (Jun 13 2023 at 15:16):

Mauricio Collares said:

Did you try testing chabulhwi.splitOn ""?

#eval chabulhwi.splitOn  "" -- ["차_!_불_!_휘_!_"]
#eval chabulhwi.splitOn' "" -- ["차_!_불_!_휘_!_", ""]

Oh. Then I suggest redefining only splitOnAux, not splitOn.

Mauricio Collares (Jun 13 2023 at 15:20):

That being said, the original function looks a bit buggy. Does "ababcab".splitOn "abc" work there? It does look like it is missing some partial match handling (KMP-style or otherwise).

Bulhwi Cha (Jun 13 2023 at 15:22):

I don't think it works.

#eval "ababcab".splitOn "abc" -- ["ababcab"]

Mauricio Collares (Jun 13 2023 at 15:23):

I probably shouldn't have used the word "buggy". Proper handling of this case would either increase memory costs or time costs, which might be undesirable depending on how the function is used. But that output is not what I expect from the function name.

Bulhwi Cha (Jun 13 2023 at 16:05):

GitHub PR: lean4#2271

Bulhwi Cha (Jun 13 2023 at 16:27):

Bulhwi Cha said:

#eval chabulhwi.splitOn  "" -- ["차_!_불_!_휘_!_"]
#eval chabulhwi.splitOn' "" -- ["차_!_불_!_휘_!_", ""]

Oh. Then I suggest redefining only splitOnAux, not splitOn.

There was a mistake: I used the old functions in the body of the redefined ones. The correct results are the following:

#eval chabulhwi.splitOn  "" -- ["차_!_불_!_휘_!_"]
#eval chabulhwi.splitOn' "" -- ["차_!_불_!_휘_!_"]

Last updated: Dec 20 2023 at 11:08 UTC