What I Learned at Work this Week: It’s a Lambda

Mike Diaz
5 min readApr 10, 2021

My experience as a developer has been punctuated by hearing others casually using words or phrases that I didn’t understand. I’ve nodded along with data streams and webhooks, EKS and API, and of course lambda. I remember first hearing about lambda functions when studying Java because “Java only uses methods, not functions…though it has lambdas…but don’t worry about that right now.” Today, we’ll start worrying about that.

The Story of Lambda

A lambda is a Greek letter that sort of looks like an isosceles triangle without a bottom. We can see a few different examples of it in the header image for this post. In the 1930s, this symbol was used by Alonzo Church to illustrate mathematical concepts in calculus, notably the abstraction of functions. Some believe that Church chose the symbol because of its similarity to a symbol for class abstraction, which used a carrot directly above a variable, but other accounts say that he merely selected it at random. In any case, we can use a lambda in calculus to write a function like this:

The first character is a lambda

I’ll admit that I didn’t know that calculus used functions, but I’m happy to report that we don’t really have to learn anything new to understand them. In algebra, just like in JavaScript, a function relates an input to an output. And as we can see in the example above, they don’t even look very different. If we removed the lambda symbol and replaced the period in the example above with an arrow, it would look like JS:

It’s not exactly JS, but at least we can read it

They’re very similar, but why does the mathematical function have to include that lambda? The symbol is used to indicate that this is an anonymous function. We might otherwise have to define the function like this:

If I looked at that very quickly, I would have assumed it was JavaScript. But that’s calculus! So when we hear someone say “lambda” at work, are they just referring to an anonymous function?

Lambdas in Programming

After hearing the word lambda so many times, it was something of a letdown to learn that it so closely resembles a very basic part of my JavaScript knowledge. If, like me, most of your exposure to code has been JS over the past few years, the impact of these anonymous functions might not resonate as it did in the past. Remember, JavaScript’s arrow syntax, which emulates a calculus lambda, was released in 2015 as part of ES6. And though its behavior can be executed with a classic ES5 function, some of its default behavior characterizes a programming lambda.

According to Wikipedia:

In lambda calculus, functions are taken to be ‘first class values’, so functions may be used as the inputs, or be returned as outputs from other functions.

This may again sound familiar if you have heard that JavaScript treats functions as first-class objects. In JavaScript, functions can be passed into other functions as arguments and functions can return other functions. And they don’t have to be anonymous or use arrow syntax to do it:

const firstFunc = function (x) {
return function (y) {
return x + y
}
};
const secondFunc = firstFunc(5);
// secondFunc is now a function that will accept an argument of y and return 5 + y
secondFunc(1)
// 6

As far as I can tell, calculus lambdas share the superficial quality of syntax with programming lambdas, but their more critical similarity, at least in JavaScript, is that they are higher-order functions that can be passed around. In other languages, like Java, the ability to create these stand-alone functions is a bit more unique, but they still carry the benefit of higher-order functions.

AWS Lambda

This is where things get tricky in the workplace, because sometimes I overhear someone say “it’s a lambda” and it’s up to me to decide whether they’re talking about a lambda function or a process executed by the AWS Lambda service. We’ve just learned that we’ve been using lambda functions all along without realizing it, so it stands to reason that if someone actually calls out a lambda, they’re talking about AWS.

AWS Lambda is a serverless computer service. I’ve actually written about serverless computing before, but for a brief refresher: it means that your processes will be run dynamically on a third party’s server, which will scale up or down depending on how much power and space you need. Serverless computing is popular because it means that companies aren’t paying for server space they aren’t using. And AWS Lambda allows them to write scripts or programs that are executed as functions when called upon.

This is super useful, but does it have anything to do with the original definition of a lambda? According to one AWS engineer, the name references the fact that the function is anonymous and is passed around, though in this case, it’s passed between AWS’ servers rather than throughout a codebase.

All Greek to me

Last week, I wrote about regex because I was short on time and felt like I already had a head start on the concept since I’ve used regular expressions before. They turned out to be a lot more complicated than I realized, so the blog took me longer than I expected (though I learned a lot). I had more time this week, so I decided to pursue something that seemed totally foreign due to its basis in calculus. As it turns out, lambdas are a pretty accessible topic, which just goes to show that we should never be discouraged to try and dive into a new subject. We might discover that we know more than we thought.

Sources:

--

--