What is a lambda (function)?

后端 未结 23 2297
太阳男子
太阳男子 2020-11-22 04:47

For a person without a comp-sci background, what is a lambda in the world of Computer Science?

23条回答
  •  太阳男子
    2020-11-22 05:13

    The question has been answered fully, I don't want to go into details. I want to share the usage when writing numerical computation in rust.

    There is an example of a lambda(anonymous function)

    let f = |x: f32| -> f32 { x * x - 2.0 };
    let df = |x: f32| -> f32 { 2.0 * x };
    

    When I was writing a module of Newton–Raphson method, it was used as first and second order derivative. (If you want to know what is Newton–Raphson method, please visit "https://en.wikipedia.org/wiki/Newton%27s_method".

    The output as the following

    println!("f={:.6}      df={:.6}", f(10.0), df(10.0))
    
    f=98.000000       df=20.000000
    

提交回复
热议问题