Happy new year, folks.
(Might not be the best place to post this, but I failed to find a better one, please advise if there is. I've also tried to look for previous comments about this. If there are, then my Google-fu was simply too weak.)
------
Usage:
(split s re)
(split s re limit)
Splits string on a regular expression. Optional argument limit is
the maximum number of splits. Not lazy. Returns vector of the splits.
------
Where I initially understand "number of splits" to be the number of matches acted upon, that's where a split occurs. I realize there's another meaning of "split", meaning fragment, and that is the one meant here. "Returns vector of the splits." hints at that as well, but it literally says "splits string on..., ... maximum number of splits.".
And even in the same docs a few lines later the example for this is phrased like this:
------
;; Note that the 'limit' arg is the maximum number of strings to
;; return (not the number of splits)
user=> (str/split "q1w2e3r4t5y6u7i8o9p0" #"\d+" 5)
["q" "w" "e" "r" "t5y6u7i8o9p0"]
------
Contradicting the upper description with "(not the number of splits)".
I've run into this more than once now, because different languages do this differently. Whenever I go to the documentation, I read the description and am satisfied that I've grokked it, just to be mocked by my off-by-one code minutes later.
Does anyone agree that this might be worth changing?
I think at least the contradiction in the example should be addressed, but I think a better solution would be to rephrase the main description to be unambiguous.
I've also looked up a few documentations in other languages. Those that limit the number of "splits" in my sense (number of matches at which to split) use the word "splits", those with a behaviour similar to that of Clojure explicitly talk about the maximum number of resulting elements/substrings/strings, and I think that would make it much clearer.
Apologies for the length!
Cheerio
Oliver