Arc Forumnew | comments | leaders | submitlogin
3 points by lg 5495 days ago | link | parent

I like this cut, except I changed the (< end 0) case to (+ (len seq) end 1). This gives the behavior I expect:

  (cut "abc" 0)
  ;=> "abc"

  (cut "abc" 0 -1)
  ;=> "abc"

  (cut "abc" -3 -2)
  ;=> "ab"
Also if anyone's interested, here's lastmatch (i.e. #1):

  (def lastmatch (pat seq)
    (catch (if (isa pat 'fn)
               (let leng (- (len seq) 1)
                 (for i 0 leng
                      (when (pat (seq (- leng i))) (throw (- leng i)))))
               (let leng (- (len seq) (len pat))
                 (for i 0 leng
                    (when (headmatch pat seq (- leng i)) (throw (- leng i))))))
           nil))