Problem 21 is: Write a function which returns the Nth element from a 
sequence.

My solution is:

(fn [[f & r] n]
        (if (zero? n)
            f
            (recur r (dec n)))))

but it is marked as incorrect. Opening a REPL, and defining it with defn:

(defn mynth
    [[f & r] n]
    (if (zero? n)
        f
        (recur r (dec n))))

user=> (mynth '(4 5 6 7 8) 2)
6

And using def + fn:

(def mynth-anon
    (fn [[f & r] n]
        (if (zero? n)
            f
            (recur r (dec n))))))

user=> #'user/mynth-anon
user=> (mynth-anon '(4 5 6 7 8) 2)
6

But (it id this result which I can't understand and the reason 4clojure 
does not like my solution) :

user=> ((fn [[f & r] n]
                (if (zero? n)
                    f
                    (recur r (dec n)))) 
            '(4 5 6 7 8 9) 
            6)
nil
user=> 

It seems I can't use an explicit anonymous recursive function in the call 
position. Is this so? Why? Is it a bug?

Thanks,

Juan Manuel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to