### 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,

Haskell, and Ocaml.

• 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...

### Read more

### Keywords

*-1*

*/blogs/lambda-expressions-java-tutorial/*

*/javase/tutorial/java/index.html*

*/javase/tutorial/java/javaoo/lambdaexpre*

*/watch?v=8pdm_kh4yky*

*/watch?v=mlksirk9nne*

*09*

*1*

*10*

*14*

*15*

*1930s*

*2*

*2014*

*3*

*4*

*5*

*6*

*7*

*8*

*abl*

*accept*

*achiev*

*action*

*action.accept*

*addit*

*adib*

*advanc*

*aho*

*[email protected]*

*ain*

*alfr*

*allow*

*alonzo*

*alreadi*

*anonym*

*anoth*

*ap*

*api*

*applic*

*aptoint*

*arbitrari*

*arg*

*argument*

*around*

*array*

*arraylist*

*arrays.aslist*

*arrrays.aslist*

*assign*

*backward*

*basic*

*becom*

*behavior*

*benefit*

*beta*

*beta-reduct*

*big*

*biggest*

*binari*

*bodi*

*brace*

*brian*

*c*

*calculus*

*call*

*captur*

*catch*

*catch-up*

*central*

*challeng*

*chang*

*channel*

*church*

*class*

*classnam*

*cnsm*

*code*

*collect*

*collection.stream*

*comma*

*common*

*compact*

*compat*

*compil*

*compon*

*comput*

*concept*

*concis*

*conjunct*

*consist*

*constructor*

*consum*

*contain*

*context*

*convert*

*could*

*creat*

*cs*

*data*

*decis*

*declar*

*default*

*defin*

*definit*

*denot*

*design*

*detail*

*develop*

*discuss*

*doc*

*docs.oracle.com*

*docs.oracle.com/javase/tutorial/java/index.html*

*docs.oracle.com/javase/tutorial/java/javaoo/lambdaexpre*

*e*

*e.g*

*e6998*

*easier*

*easier-to-understand*

*effect*

*eight*

*element*

*elimin*

*enabl*

*enclos*

*equival*

*er*

*evalu*

*exact*

*exam*

*exampl*

*exclud*

*exist*

*expect*

*explicit*

*expr*

*express*

*facilit*

*featur*

*fi*

*filter*

*final*

*first*

*flexibl*

*focus*

*follow*

*for-loop*

*foreach*

*formal*

*framework*

*full*

*function*

*functional-styl*

*generat*

*generic*

*genn*

*get*

*getcolor*

*getw*

*given*

*go*

*goetz*

*grammar*

*haskel*

*hood*

*idget*

*idgets.stream*

*immut*

*imper*

*implement*

*import*

*incept*

*incorpor*

*infer*

*inform*

*insid*

*instanc*

*instancemethodnam*

*int*

*integ*

*interact*

*interfac*

*intermedi*

*introduc*

*intseq*

*intseq.foreach*

*invok*

*io*

*item*

*java*

*java.util.function*

*java.util.stream*

*keep*

*lambda*

*lambda-calculus*

*lambdacalculus*

*languag*

*lazi*

*leaner*

*lectur*

*like*

*lisp*

*list*

*list.stream*

*local*

*longer*

*loop*

*lot*

*lter*

*lvc*

*m*

*machin*

*major*

*mani*

*map*

*match*

*materi*

*mathemat*

*method*

*methodnam*

*model*

*much*

*multilin*

*must*

*name*

*need*

*new*

*non*

*non-default*

*note*

*notic*

*number*

*object*

*objectrefer*

*obtain*

*ocaml*

*one*

*one-to-on*

*onsum*

*open*

*oper*

*ordinari*

*out.println*

*outlin*

*outsid*

*packag*

*parallel*

*paramet*

*parenthes*

*parenthesi*

*part*

*pass*

*peek*

*perform*

*pipelin*

*place*

*play*

*ple*

*power*

*predic*

*prefer*

*println*

*privat*

*problem*

*produc*

*program*

*properti*

*provid*

*public*

*publish*

*r*

*rather*

*recent*

*recompil*

*recurs*

*red*

*reduc*

*reduct*

*refer*

*referenc*

*referenti*

*repres*

*requir*

*result*

*return*

*reusabl*

*rewrit*

*saikali*

*see*

*select*

*separ*

*septemb*

*sequenti*

*serv*

*side*

*signatur*

*sinc*

*singl*

*single-stat*

*sourc*

*specif*

*specifi*

*squar*

*ssions.html*

*statement*

*static*

*staticmethodnam*

*stream*

*string*

*style*

*sum*

*summari*

*support*

*svcexam*

*syntax*

*system*

*system.out.println*

*take*

*termin*

*think*

*three*

*topic*

*tostr*

*total*

*transform*

*transpar*

*treat*

*ture*

*tutori*

*type*

*under*

*understand*

*us*

*usabl*

*use*

*usual*

*util*

*v*

*valu*

*valueof*

*var*

*variabl*

*via*

*viralpatel.net*

*viralpatel.net/blogs/lambda-expressions-java-tutorial/*

*void*

*w*

*way*

*weight*

*well*

*wide*

*widget*

*wish*

*without*

*would*

*write*

*written*

*www.youtube.com*

*www.youtube.com/watch?v=8pdm_kh4yky*

*www.youtube.com/watch?v=mlksirk9nne*

*x*

*y*

*zero*

*λ*