Search code examples
functionlambdafunctional-programmingprocedural

Lambda Expressions vs Procedural-styled Functions


I just don't understand the power of the lambda expression.

Python

def sum(x, y):
    return x + y

Scheme

(lambda (x y) (+ x y))

Why is one so different from the other besides the lambda expression not being given a formal name? It seems like you can do the same things with either method, so why is my teacher so high on the lambda calculus?


Solution

  • Intuitively when we compare two tools we think about what one of them achieve that the other can't so that we can understand the benefit of one over the other, but in this particular case both the tools (Procedural and Functional) are equivalent in terms of what you can achieve with them i.e what computations you can perform.

    The above situation is what makes people confuse when start learning Functional programming, as they start comparing what can be achieved in one that can't be done in another.

    Now if you face a situation where you have 2 tools, lets say 2 washing machines (hypothetically - one from planet A and other from planet B), and they achieve the same quality of washing for different detergents, how would you approach to compare them and figure out the differences? The only possible way to differentiate is how they achieve the result i.e tear apart the washing machines and start looking at the internals of them to figure out how they achieve the result and that will lead you to the conclusion that "The difference between the two washing machine is that the primitive components (the nuts, the bolts, the circuit etc) and how they are composed/attached together to achieve the results are different in both of the machines".

    Based on above observation you could say - The lambda calculus and procedural approach have different primitives and they have different approach to compose/attach these primitives to perform the desired computations.