1. Those great names are related to the history of javascript creation?
Yes, when referring to names used in JavaScript, the naming conventions were mostly to make JavaScript easy for a novice to understand. The language itself was built to be very simple, to be embedded right into the html page. It did borrow some naming styles from other languages but its ultimate goal was simplicity.
2. Lambda expression is just => ?
Close but it is the full expression
(x, y, z) => x + y +z;
“is used to bind variables to values which are then evaluated within an expression” that is the lambda expression. Lambda uses an arrow as one of its operators C# uses “ => “ in its place. The part in parentheses is the variables which point to, or are bound to the arguments that they receive from the right side of the pointer.
3. But where did mathematician talk about "lambda expression"?
Without going into too much detail back in the 1930's a mathematician named
Alonzo Church amongst others worked on mathematical formulas they referred to as
Lambda Calculus, or Church's Theorem, stating that the
recursive functions are the only functions that can be mechanically calculated. The theorem implies that the procedures of arithmetic cannot be used to decide the consistency of statements formulated in accordance with the laws of arithmetic.
In 1956 American social scientist and Nobel laureate Herbert Simon and American physicist and computer scientist Allan Newell at Carnegie Mellon University in Pennsylvania devised a program called
Logic Theorist that simulated human thinking on computers. In the course of their work on the Logic Theorist and GPS, Allan Newell, Herbert Simon, and Shaw developed their
Information Processing Language (IPL), a computer language tailored for AI programming. At the heart of IPL was a highly flexible data structure that they called a list.
In 1960 John McCarthy combined elements of IPL with the lambda calculus to produce the programming language LISP (List Processor). LISP a list-oriented computer programming language was used primarily to manipulate lists of data.
JavaScript’s is often said to have more in common with LISP than to C from where it gets its syntax, but from LISP is where it get its functionality
JavaScript is the first lambda language to go mainstream. Deep down, JavaScript has more in common with LISP than with Java. It is LISP in C’s clothing.
Douglass Crawford: JavaScript: The Good Parts.
So in essence JavaScript got a lot of functional programming logic from LISP while LISP got it from LOGIC and LOGIC got it from Lambda Calculus. The name Lambda or L stood for arithmetic logic. This is similar how we got BOOLEAN LOGIC in JavaScript from Boolean algebra from George Boole.
3. One question you seems did not answered me (perhapse you answered but in some way I cannot perceive.) is
"if this code is used only once (hence no need for a name), why use function?"
The function is only referenced back to through its prototype, thus it is reused through reference but not through a new action. Thus new objects that you create refers back to it for its own data structure and layout.
var Person ={
firstName: “SomeName”,
lastName: “TheirLastName”,
fullName: function(){
return this.firstName + “ “ + this.lastName
}
};
the anonymous function actually is the value of fullName in this example, thus every time that you create the Person object “
this.firstName” is concatenated with “
this.lastName” and becomes the value of
fullName. You will see others write the code differently at times where the Person or custom may have parameters and receive a number of arguments; both ways a perfectly valid. There are times though when you may wish that a function is used only once such as a custom function created to submit payment.
Programmers sometime make function non-reusable to avoid individuals from either ordering or making duplicate payments. The bottom line is that it will be referenced back to through its object or variable name but not through its own.
copy this in your text editor for now do not change the bolded function but create duplicates of John and Mary, changing the names. this is a very small data structure. Now imagine if it were a building with data containing, height, width, widows, electrical, material, heating, cooling and pricing data. It could all be stored much easier by creating a prototype
(a mini data base if you will)then referenced only by
this.buildingInfo
function Person(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
this.fullName = function(){
return this.firstName + " " + this.lastName;
}
}
var John=new Person ("John", "Doe");
var Mary = new Person("Mary ", "Jane");
alert(John.fullName ());
This post has been edited by AndPog7: 20 July 2012 - 03:51 AM