[CLJ-717] A range function for characters, char-range Created: 15/Jan/11 Updated: 16/Jan/11 Resolved: 15/Jan/11
I've seen a lot of cases where people would do stuff like this:
Or other equally meh things in order to get a range of characters. Haskell's range supports creating ranges of characters, so that was inspiration for this addition.
I've created a function that is the analogue of range for characters. I've called it char-range. It works almost precisely the same as range (and uses range under the hood), only the upper bound isn't exclusive. It made more sense to me for it to be inclusive, so that things like (char-range \a \z) work and make sense.
It takes the same argument combinations as range. For no arguments, it produces a lazy sequence of characters from Character/MIN_VALUE to Character/MAX_VALUE. For two arguments, it produces a lazy sequence from Character/MIN_VALUE to end. It allows for the same stepping that range allows for as well.
|Comment by Anthony Simpson [ 15/Jan/11 10:29 AM ]|
A friend pointed out to me that I shouldn't have set the issue's approval to 'Test'. I took "If the ticket has (or you write) a patch that applies, test it. If it seems to work, set the status to "Test."" out of context. I don't see a way to set the Approval back to "None", so I'm just going to apologize and whistle.
|Comment by Stuart Halloway [ 15/Jan/11 4:30 PM ]|
Before implementing a feature like this, please document the problem and the other possible solutions/variants. Some things to think about:
If you want, please start a design discussion at http://dev.clojure.org/display/design/Home
|Comment by Scott Olson [ 15/Jan/11 6:14 PM ]|
It's a lot easier to tell that (char-range \a \z) is correct than "abcdefghijkmnopqrstuvwxyz" (did you notice the missing character at a glance?).
Why would you need to know the character after Z? The OP clearly said the upper bound would be inclusive.
As for performance, char-range uses the functions map and range which are themselves built in a fast low-level way, so as long as they perform well, so will char-range.
|Comment by Stuart Halloway [ 16/Jan/11 9:12 AM ]|
So range will be exclusive while char-range will be inclusive? Tough sell. You will need more motivation that this one example.
I am not saying this couldn't be the right patch. I am saying that the hard part is answering the design questions, which has to come first. Also, threaded comments on a patch isn't the best place to do it. If char-range is important enough to you, then please start a design page under http://dev.clojure.org/display/design/Home.