## 14 09 15 Essay

### Essay preview

Alfred V. Aho
[email protected]

Lecture 2: Design and Implementation
of Lambda Expressions in Java 8

CS E6998-1: Advanced Topics in
Programming Languages and Compilers
September 15, 2014

Outline
1.
2.
3.
4.
5.
6.
7.

What is the lambda calculus?
What is functional programming?
What are the benefits of functional programming?
Functional programming in Java 8
Java 8 lambda expressions
Implementation of Java 8 lambda expressions
Streams

The Lambda Calculus
• The lambda calculus was introduced in the 1930s by Alonzo Church as a mathematical system for defining computable
functions.
• The lambda calculus is equivalent in definitional power to that of Turing machines.
• The lambda calculus serves as the computational model
underlying functional programming languages such as Lisp,
• Features from the lambda calculus such as lambda expressions have been incorporated into many widely used programming
languages like C++ and now very recently Java 8.

What is the Lambda Calculus?
• The central concept in the lambda calculus is an
expression generated by the following grammar
which can denote a function definition, function
application, variable, or parenthesized expression:
expr → λ var . expr | expr expr | var | (expr)
• We can think of a lambda-calculus expression as a
program which when evaluated by beta-reductions
returns a result consisting of another lambdacalculus expression.

Example of a Lambda Expression
• The lambda expression

λ x . (+ x 1) 2
represents the application of a function λ x . (+ x 1)
with a formal parameter x and a body + x 1 to the
argument 2. Notice that the function definition
λ x . (+ x 1) has no name; it is an anonymous
function.
• In Java 8, we would represent this function definition
by the Java 8 lambda expression x -> x + 1 .

More Examples of Java 8 Lambdas
• A Java 8 lambda is basically a method in Java without a
declaration usually written as (parameters) -> { body }. Examples, 1. (int x, int y) -> { return x + y; }
2. x -> x * x
3. ( ) -> x

• A...