How do you read a lambda expression?

Hi All,

I am trying to figure out how to read out loud a lambda expression.  For example if I have the following

i => (i %2) == 0 or c => c.Age < 50 etc.

How would I read them to my children

Cheers,

Clint




Answer this question

How do you read a lambda expression?

  • Db88Master

    personally, i love the lambda expression additions.

    in school, i used SML most of the time, and it was an amazing language.

    i know lamba expressions are probably a little foreign for a lot of programmers,

    but the power of being able to inline functions creates many possibilities for streamlined implementations.

    give it a chance, and then you probably will wonder where they have been your whole life.

     



  • AE-Sol

    I've always read it as 'in which':

    "c in which Age is less than 50"

    etc.



  • Rookie

    I think how a lambda expression is read depends on the context in which it is used.  For example,

    In numbers.Where(num => num < 5), the lambda expression is a predicate, so the lambda can naturally be read as "num where num is less than 5".

    In numbers.Select((num, index) => new {Num = num, InPlace = (num == index)}), the lambda expression is a projection selector, so I would read it as "num, index, selecting Num as num, InPlace as num equals index".

    Verbalizing out of context is a little more arcane, but the fact that the lambda expression is really an anonymous method means it makes sense to vocalize the function call and say something like:
    "num, calling num less than 5"
    "num, index, calling new Num equals num, InPlace as num equals index"

    -Mathew



  • Duncan Woods

    so maybe read it like

    "i lambda returns true when i mod 2 is equal to 0"

    Cheers,

    Clint



  • Eagle 101

    I would read it like:

    i => (i %2) == 0: returns true when i is even

    c => c.Age < 50 : returns true when c's age is below "way too old"



  • Boise83716

    I think they are fantastic as well since they make the code more visually readable but I am still trying to figure out if there is an official way to read it out loud.

    Cheers,

    Clint



  • How do you read a lambda expression?