On Mon, Oct 28, 2013 at 11:48 AM, Jesse Ruderman <[email protected]> wrote:
> If you don't mind changing ntimes to not return a closure:
>
> fn ntimes<T>(f: &fn(T) -> T, times: uint, x: T) -> T {
>     match times {
>         0u => x,
>         _  => ntimes(|x| f(x), times - 1u, f(x))
>     }
> }
>
> fn main() {
>     println(format!("{:d}", ntimes(|k| k*2, 2u, 3)));
> }

Thanks. That is very nice.

No, I am not particular about returning a closure. I was just trying
out some toy programs to learn Rust.

It would have been nice to return a closure from `ntimes' though. :(

-- 
  Ramakrishnan
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to