SlideShare a Scribd company logo
Project Lambda  or #()(”Project Lambda”) 2010-04-29
Lambda Expressions (aka Closures) “ a first-class function with free variables that are bound in the lexical environment” - Wikipedia HUGE debate about various closures decision earlier BGGA, CICE, FCM, …  Oracle seems to have decided this without JSR/JCP - most likely that this will be included in Java 7 Straw-Man Proposol - first-class functions  - function types  - lambda expression Syntax and content not definite, may change Complexity budget reached?
Lambda Expressions – Suggested Syntax A new way of writing anonymous functions A functions which take an int and returns its double #() (42) //no args, returns 42 #(int x) (x+x)
Lambda Expressions Complex expressions #(int x, int y){ int z = expensiveComputation(x, y);  if (z < 0) return x;  if (z > 0) return y;  return 0;    }
Function Types Every expression in Java must have a type, i.e. introduce  function types … and they could be invoked #int() fortyTwo = #()(42);  #int(int) doubler = #(int x)(x + x);  assert fortyTwo() == 42;  assert doubler(fortyTwo()) == 84;
Functions as arguments Methods can take a function as an argument public int[] map(int[] a, #int(int) fn) {  int[] b = new int[a.length];  for (int i = 0; i < a.length; i++)  b[i] = fn(a[i]);  return b;  }
SAM types Interfaces with just one method (SAM) Thread th = new Thread(new Runnable() {  public void run() {  doSomeStuff();  doMoreStuff(); } });  Thread th = new Thread(#(){  doSomeStuff();    doMoreStuff(); } )
Variable Capture shared  int count = 0;  Collections.sort(data, #(String a, String b){  count++;  return a.length() - b.length()}); System.out.println(count);

More Related Content

PPTX
Syntax Comparison of Golang with C and Java - Mindbowser
PPTX
Pointers Refrences & dynamic memory allocation in C++
PPT
Testing for share
PPT
C# programming
PPTX
Pointers, virtual function and polymorphism
PPT
Structures
PPTX
pointer, virtual function and polymorphism
PPTX
Javascript Tip and Triks
Syntax Comparison of Golang with C and Java - Mindbowser
Pointers Refrences & dynamic memory allocation in C++
Testing for share
C# programming
Pointers, virtual function and polymorphism
Structures
pointer, virtual function and polymorphism
Javascript Tip and Triks

What's hot (20)

PDF
Regular types in C++
PPT
Strings In OOP(Object oriented programming)
PPTX
C++ concept of Polymorphism
ODP
Clojure basics
PDF
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
PDF
Big picture of category theory in scala with deep dive into contravariant and...
PDF
Java 5 New Feature
PPTX
C++11: Feel the New Language
PPT
Introduction to Laws
PPTX
Modern C++
PPT
Jeop game-final-review
PPT
Paradigmas de Linguagens de Programacao - Aula #5
PDF
C interview questions
PPTX
C++ 11 Features
PDF
Linked list
PDF
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
PPTX
C traps and pitfalls for C++ programmers
PDF
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
PPTX
Functional programming
PDF
Smart Pointers in C++
Regular types in C++
Strings In OOP(Object oriented programming)
C++ concept of Polymorphism
Clojure basics
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Big picture of category theory in scala with deep dive into contravariant and...
Java 5 New Feature
C++11: Feel the New Language
Introduction to Laws
Modern C++
Jeop game-final-review
Paradigmas de Linguagens de Programacao - Aula #5
C interview questions
C++ 11 Features
Linked list
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
C traps and pitfalls for C++ programmers
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Functional programming
Smart Pointers in C++
Ad

Viewers also liked (8)

PPTX
Behavior-driven Development and Lambdaj
PPTX
Java Extension Methods
PPT
PPTX
Software Craftsmanship
PPTX
BDD Short Introduction
PPTX
Java7 - Top 10 Features
PPTX
Hybrid Applications
PPT
SOLID Design Principles
Behavior-driven Development and Lambdaj
Java Extension Methods
Software Craftsmanship
BDD Short Introduction
Java7 - Top 10 Features
Hybrid Applications
SOLID Design Principles
Ad

Similar to Project Lambda - Closures after all? (20)

PPTX
Functional Programming In Jdk8
PDF
Project Lambda, JSR 335
PPTX
Lambda functions in java 8
PDF
JSR 335 / java 8 - update reference
PPTX
Java gets a closure
PDF
Java 8 Lambda Expressions & Streams
PDF
Java 8-revealed
PDF
Hanoi JUG: Java 8 & lambdas
PDF
Java 8
PDF
Lambdas in Java 8
PPS
Let Us Learn Lambda Using C# 3.0
PDF
Scala is java8.next()
PDF
Eclipse and Java 8 - Eclipse Day India 2013
PDF
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
PDF
PPTX
It's Java, Jim, but not as we know it
PPTX
Java 8 features
PPTX
It's Java Jim, But Not As We Know It!
PPTX
The Road to Lambda - Mike Duigou
PDF
Lambda Expression For anyone that needs Java Lambda notes
Functional Programming In Jdk8
Project Lambda, JSR 335
Lambda functions in java 8
JSR 335 / java 8 - update reference
Java gets a closure
Java 8 Lambda Expressions & Streams
Java 8-revealed
Hanoi JUG: Java 8 & lambdas
Java 8
Lambdas in Java 8
Let Us Learn Lambda Using C# 3.0
Scala is java8.next()
Eclipse and Java 8 - Eclipse Day India 2013
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
It's Java, Jim, but not as we know it
Java 8 features
It's Java Jim, But Not As We Know It!
The Road to Lambda - Mike Duigou
Lambda Expression For anyone that needs Java Lambda notes

Project Lambda - Closures after all?

  • 1. Project Lambda or #()(”Project Lambda”) 2010-04-29
  • 2. Lambda Expressions (aka Closures) “ a first-class function with free variables that are bound in the lexical environment” - Wikipedia HUGE debate about various closures decision earlier BGGA, CICE, FCM, … Oracle seems to have decided this without JSR/JCP - most likely that this will be included in Java 7 Straw-Man Proposol - first-class functions - function types - lambda expression Syntax and content not definite, may change Complexity budget reached?
  • 3. Lambda Expressions – Suggested Syntax A new way of writing anonymous functions A functions which take an int and returns its double #() (42) //no args, returns 42 #(int x) (x+x)
  • 4. Lambda Expressions Complex expressions #(int x, int y){ int z = expensiveComputation(x, y); if (z < 0) return x; if (z > 0) return y; return 0; }
  • 5. Function Types Every expression in Java must have a type, i.e. introduce function types … and they could be invoked #int() fortyTwo = #()(42); #int(int) doubler = #(int x)(x + x); assert fortyTwo() == 42; assert doubler(fortyTwo()) == 84;
  • 6. Functions as arguments Methods can take a function as an argument public int[] map(int[] a, #int(int) fn) { int[] b = new int[a.length]; for (int i = 0; i < a.length; i++) b[i] = fn(a[i]); return b; }
  • 7. SAM types Interfaces with just one method (SAM) Thread th = new Thread(new Runnable() { public void run() { doSomeStuff(); doMoreStuff(); } }); Thread th = new Thread(#(){ doSomeStuff(); doMoreStuff(); } )
  • 8. Variable Capture shared int count = 0; Collections.sort(data, #(String a, String b){ count++; return a.length() - b.length()}); System.out.println(count);