Arc Forumnew | comments | leaders | submit | rapp's commentslogin
1 point by rapp 5916 days ago | link | parent | on: New version

Better yet, the addition of the language features, brevity, and power of K [ http://www.kuro5hin.org/story/2002/11/14/22741/791 ]

-----


(if (< end 0) (= end (+ end (len seq))))

(if (< start 0) (= start (+ start (len seq))))

-----

4 points by scn 5929 days ago | link

That gives

  (subseq "hello" 0 -1)
  "hello"
I was going for

  (subseq "hello" 0 -1)
  "hell"
to match python's

  "hello"[:-1]
  "hell"

Are reverse strings 0 or -1 indexed? :)

-----

3 points by mdemare 5929 days ago | link

Both. They use ranges, with have the inclusive (..) and the exclusive notation:

    "ruby"[0 .. -1] #=> "ruby"
    "ruby"[0 ... -1] #=> "rub"

-----

2 points by nex3 5929 days ago | link

Ruby does it the other way:

  > "hello"[-3..-1]
  "llo"
However, given that we can do something like

  > (subseq "hello" -4)
  "ello"
if we want to take the last n characters, doing zero-based reverse indexing might make more sense.

-----

2 points by oddbod 5928 days ago | link

Tcl lrange: http://tcl.tk/man/tcl8.5/TclCmd/lrange.htm

    (subseq "hello" 0 'end)
    "hello"
    (subseq "hello" 0 -1)
    "hell"

-----

2 points by rapp 5929 days ago | link

Your 100% right. I was blindly matching the test case:

    > (subseq "foobar" 2 -2)
    "oba"

-----

2 points by rapp 5929 days ago | link | parent | on: Clarification about Character Sets

Arc is a powerful gesture to the ratification of the very concept of language design. Simply stated the language is in our hands to insure its evolution.

-----