Last + butlast?

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

> Found the answer :
>
> (defn secondlast [coll]
>     (let [number 0
>           counter (- (count coll)2) ]
>       (loop [coll coll counter counter number number]
>         (if (= counter number)
>           (first coll)
>           (recur (next coll) counter (+ number 1))))))
>
> and without the loop there will be : (first(drop(reverse v))
>
> Roelof
>
>
> Op dinsdag 6 mei 2014 13:36:53 UTC+2 schreef Roelof Wobben:
>>
>> As far as I understand recur is going back to the loop  so number is
>> never going back to 0
>> but I see the problem (-(count coll)2 is changing it value and that
>> schould not happen.
>> So I think I have to set the initial value of counter in the let.
>>
>> what schould happen is this
>>
>>        coll            number    counter
>> 1)   [1,2,3.4.5)     0             3
>> 2)   [2.3,4,5]        1             3
>> 3)   [3,4,5]           2             3
>> 4) [ 4,5]               3             3
>>
>> so the (first coll) is executed which is 4.
>>
>> Am I at the right track now.
>>
>>
>>
>> Roelof
>>
>>  --
> 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<javascript:_e(%7B%7D,'cvml','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<javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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<javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');>
> .
> For more options, visit https://groups.google.com/d/optout.
>

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