Most of the way down the page at the section "Syntax of Lambda Expressions". I maybe looking right at it and not seeing it. I do see it called out: "The arrow token, ->", but not defined that I can tell. Please help me understand this.
The arrow is part of the syntax of a λ. You know you write λ x • x + 2 and that means that (λ x • x + 2)y will evaluate to y + 2? Well, you cannot write • because there isn't a • key on most keyboards, not even with AltGr. So they came up with a new operator using two keystrokes which are usually found on keyboards − and >.
The part before the • goes to the left of the -> in () but you can omit the () if there is only one argument. Then the arrow token replaces the •. Then the remainder goes afterwards. So my λ x • x + 2 comes out as x -> x + 2
By the way: how do people pronounce -> when reading out code? I have never seen it anywhere.
Edit: additional link to maths tutorial as PDF.
Dustin Wright wrote: I took a look at your PDF, it appears this is related to calculus. I have no knowledge of calculus, so I'm guessing I may not be able to understand the meaning of "->". If possible, please dumb this down as far as you can just in case. I literally have no knowledge of any mathematics beyond arithmetic.
No, Lambda expressions are not related to calculus, they are related to mathematical functions. In java they are just syntactic sugar to make it easier to create an object that meets a particular type of interface, and wherever you see a lambda expression you could replace it with an anonymous class declaration. Lambda expressions are much more readable though, so make functional programming styles much more accessible in java.
To answer your question Campbell, I normally read the arrow operator as 'goes to', or 'evaluates to'.
I would read 'a goes to 2a'
Assuming I have p, then create a "method" where System.out.println(p) is done. Method is in quotes because it isn't really a method, but at the beginning you can think of it that way.
"Give me the n and I'll square it."
Does that make sense?
Campbell Ritchie wrote:(...)but it is completely different from differential and integral calculus which Newton invented.
That was Leibniz!
But I guess you also say the English invented football...
Anyway: in the first class of high school I learned to write functions like this:
f: x -> 3x + 1
later to be replaced by f(x) = 3x + 1.
So the lambda notation reminds me of the goold old days when I was young...