You have a number of typos, syntax errors and missing brackets in your
source code. It should be:

(defn nth* [coll number]
  (loop [coll coll, acc 0]
    (if (= acc number)
      (first coll)
      (recur (next coll) (+ acc 1)))))

Additionally, you're using an unquoted list to test. Use a vector or quote
the list:

(nth* [1 2 3 4 5] 2)

- James


On 6 May 2014 16:05, Roelof Wobben <rwob...@hotmail.com> wrote:

> I tried this problem again.
>
> So I did this:
>
> (defn nth* [coll, number]
>    (let [acc 0]
>    (loop [coll coll acc]
>      (if == acc number))
>        (first coll)
>        (recur (next coll) (+acc 1 ))
>
> but when I do :
> (nth* (1,2,3,4,5)2)) I see a cannot cast error message.
>
> Is this because Clojure cannot figure out what the coll and what the
> number is ?
>
> Roelof
>
>
>
> Op woensdag 30 april 2014 12:53:01 UTC+2 schreef James Reeves:
>
>> On 30 April 2014 11:41, Roelof Wobben <rwo...@hotmail.com> wrote:
>>>
>>>
>>> Op woensdag 30 april 2014 12:14:39 UTC+2 schreef James Reeves:
>>>>
>>>>
>>>> Consider how you might add a counter to the loop. You'll want to
>>>> increment the counter, then stop when it reaches the desired number.
>>>>
>>>
>>>
>>> So without checking it so out of my head I would do this
>>>
>>>  (defn last* [coll, number]
>>>    (loop [coll coll]
>>>      (if == counter number))
>>>        (first coll)
>>>        (recur (next coll) (+counter 1 ))
>>>
>>
>> Essentially yes. You need to initiate the counter to zero, and you still
>> need a condition to make sure you don't go past the end of the seq (in case
>> n is more than the length of the list), but you've basically got it.
>>
>> - James
>>
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to