Re: Recursive anonymous functions in the call position

2012-03-16 Thread JuanManuel Gimeno Illa
Thanks !!! 

It's wonderful how much time can be wasted because a bad copy&paste :-)

Juan Manuel

On Friday, March 16, 2012 9:39:09 AM UTC+1, Meikel Brandmeyer (kotarak) 
wrote:
>
> Hi,
>
> there is no 6th element in your example. That's why you get nil.
>
> Clojure 1.3.0
> user=> ((fn [[f & r] n] (if (zero? n) f (recur r (dec n [4 5 6 7 8 9] 
> 2)
> 6
>
> Sincerely
> Meikel
>
>

-- 
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

Re: Recursive anonymous functions in the call position

2012-03-16 Thread Meikel Brandmeyer (kotarak)
Hi,

there is no 6th element in your example. That's why you get nil.

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

Sincerely
Meikel

-- 
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

Recursive anonymous functions in the call position

2012-03-16 Thread JuanManuel Gimeno Illa
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