Arc Forumnew | comments | leaders | submitlogin
1 point by akkartik 5502 days ago | link | parent

I like your approach; here's mine in similar style:

    (let old-cut cut
      (def cut (seq start (o end))
        (old-cut seq
                 (if (start < 0)
                   (+ (len seq) start)
                   start)
                 end)))
I'm having a hard time assessing the use case, though. Are you trying to avoid +1, etc.?

Also, sometimes the calculations are just as easy to do in positive indices.



1 point by rocketnia 5502 days ago | link

I've searched through lots of the code I've written, and as it turns out, I haven't found one case where being having 0 as a "negative" index would have helped. :-p So while I still like it better my way, I don't have a real use case to show.

From another standpoint, maybe it's just that I don't want to rely on the behavior of something like (cut '(1 2 3 4) 3 1), where the indices are reversed. If I can exempt (cut '(1 2 3 4) -3 0) from that error/undefined zone (in a way that's smoothly consistent with cut's other behavior), then cut may be slightly more useful to me at some point. But yeah, I don't know exactly when it would pay off or whether some other behavior would be better.

-----