Arc Forumnew | comments | leaders | submitlogin
1 point by immanuel 6119 days ago | link | parent

"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.


1 point by sjs 6118 days ago | link

"aoeui"[3:1] ??? "aoeui"[12:42] ?? "aoeui"[0:0]

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.

    >>> s="aoeui"
    >>> s[3:1]
    ''
    >>> s[4:-3]
    ''
    >>> s[9:-20]
    ''
    >>> s[0:-0]
    ''
    >>> s[12:42]
    ''

-----

1 point by mec 6118 days ago | link

Why not return the reverse when going backwards within bounds?

    >>> s="aoeui"
    >>> s[3:1]
    "eoa"
    >>> s[4:-3]
    "ue"
    >>> s[9:-20]
    ''
    >>> s[0:-0]
    'a'
    >>> s[12:42]
    ''

-----

2 points by sjs 6118 days ago | link

That is too magic for my taste. [0:-0] returning the first char is madness. That should be '' no matter what, as 0 == -0 on modern cpus (thankfully).

-----

6 points by noahlt 6119 days ago | link

It just takes getting used to, like prefix notation.

-----