Advertisement
Guest User

Untitled

a guest
Jul 20th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn adjust-index
  2.   ([vector index]
  3.      (cond  (neg? index) (+ (count vector) index)
  4.             (<= (count vector) index) (- index (count vector))
  5.             (number? index) index))
  6.   ([map x y]
  7.      (list (adjust-index map x) (adjust-index (nth map x) y))))
  8.  
  9. (def a '((1 2) (3 4)))
  10. (adjust-index a 1 -1)  ;; (1 1)
  11. (adjust-index a -1 1)  ;; java.lang.IndexOutOfBoundsException||
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement