Arc Forumnew | comments | leaders | submitlogin
4 points by babo 6078 days ago | link | parent

This patch against arc.arc gives you similar functionality:

  (def subseq (seq start (o end (len seq)))
  -  (if (isa seq 'string)
  -      (let s2 (newstring (- end start))
  -        (for i 0 (- end start 1)
  -          (= (s2 i) (seq (+ start i))))
  -        s2)
  -      (firstn (- end start) (nthcdr start seq))))
  +  (with (
  +    start (if (< start 0) (+ (len seq) start) start)
  +    end (if (< end 0) (+ (len seq) end) end)) 
  +    (if (isa seq 'string)
  +        (let s2 (newstring (- end start))
  +          (for i 0 (- end start 1)
  +            (= (s2 i) (seq (+ start i))))
  +          s2)
  +        (firstn (- end start) (nthcdr start seq)))))

  (subseq "hello" 0 -1) => "hell"
  (subseq "hello world" -5) => "world"
  (subseq "hello world" -4 -2" => "or"
Interpreting the second parameter as an offset if it's greater than 0 probably much more useful, I'll try it out later today.