The one way that it might not work so hot in an s-expression is Python's blanking-out of indexes to indicate the default, e.g.,
"abcdefghi"[::-2] #=> "igeca"
I'd like to see as much of this sort of range functionality as possible -- it's quite convenient -- but in an s-expression the above would be something like
("abcdefghi" -2) ;no distinction!
Perhaps use _ or some other symbol for the default? The cleanest would probably be to stick to the one-plus-optional-second-or-third format and just have a function that collects every nth element (then negative steps with default begins / ends would also be a chain of rev and firstn / nthcdr). Just my two cents.
I've changed subseq (whose name is also going to become cut).
I don't want to add the second arg in string references, though, because omitting the cut implies you're getting a pointer within the original string, which you could then modify by setting elements.
Are pointers within strings useful? I.e. would be it be useful if this worked:
arc> (= ss "foobar")
"foobar"
arc> (= ((ss 2 -2) 0) #\x)
#\x
arc> ss
"foxbar"
There's no built-in way to get make a var point into the middle of a string in MzScheme, but I could make it happen if there was a need for it.
Hmm. The obvious implementation to me seems to be this:
(def slice (seq start (o end (len seq)))
(subseq seq (mod start (len seq)) (mod end (len seq))))
However, this would give slice meaning for indices outside the length of the sequence, by modding them back into the range. Is this ever actually useful? (Perhaps in some sort of loop that doesn't know the range of the sequence? Maybe you want something that looks like an infinitely long sequence but is actually a cycle of some length?)
"asdfa"[4..-3] ???
"asdfa"[9 -20] ??
"asdfa"[0..-0] ??
Only seems to make reasoning about code more difficult in return for brevity. Helpful for programmers whose main productivity obstacle is typing speed.
With or without negative indices one can do pointless things with slicing/subseq. Returning an empty string/list is the only sane thing to do in those cases.