Skip to content

@rubysolo /my-nth.clj
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
my-nth
user=> (defn my-nth [s n] (first ((apply comp (repeat n rest)) s)))
#'user/my-nth
user=> (my-nth '(4 5 6 7) 2)
6
---
On 4clojure:
#21:
(= (__ '(4 5 6 7) 2) 6)
My entry:
(fn my-nth [s n] (first ((apply comp (repeat n rest)) s)))
java.security.PrivilegedActionException: java.lang.IllegalArgumentException: Wrong number of args (0) passed to: core$comp (NO_SOURCE_FILE:0)
---
In the REPL:
user=> (= ((fn my-nth [s n] (first ((apply comp (repeat n rest)) s))) '(4 5 6 7) 2) 6)
true
---
comp requires at least one argument (thx amalloy)
which might be considered a bug:
http://blog.fogus.me/2010/08/18/monkeying-with-clojures-comp-function/
fixed version:
(defn my-nth [s n]
(if (= 0 n)
(first s)
(first ((apply comp (repeat n rest)) s))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.