Thursday, 1 November 2012

Flipping Out Continued

And to test the flip-out function I needed a function that takes three parameters where the order matters.  So I added this:

(defn drop-take
  "Drop i elements from the sequence s and then take j of what's left"
  [i j s]
  (take j (drop i s)))

Then to test:

user=> (drop-take 10 5 (range))
(10 11 12 13 14)

user=> ((flip-out drop-take) 5 10 (range))
IllegalArgumentException Don't know how to create ISeq from: java.lang.Long  clojure.lang.RT.seqFrom (

Ha - pay attention - arguments in the reverse order, remember?

user=> ((flip-out drop-take) (range) 5 10)
(10 11 12 13 14)

That's more like it.

I'm puzzled that I had to rebuild the parameter list by writing

([x y & more] (apply f (reverse (cons x (cons y more)))))

I thought this might work:

([x y & more :as s] (apply f (reverse (s)))

But no, more research required...

No comments:

Post a Comment