Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a lambda language?

I was reading "JavaScript: The Good Parts" and the author mentions that JavaScript is the first of the lambda languages to be launched.

JavaScript's functions are first class objects with (mostly) lexical scoping. JavaScript is the first lambda language to go mainstream. Deep down, JavaScript has more in common with Lisp and Scheme than with Java. It is Lisp in C's clothing. This makes JavaScript is remarkably powerful language.

I didn't get what is a lambda language. What are the properties of such a language and how is it different from languages like Java, C, C++ and Php?

like image 258
sushil bharwani Avatar asked Oct 05 '10 15:10

sushil bharwani


People also ask

What is lambda is used for?

LaMDA was built on Google's open-source neural network, Transformer, which is used for natural language understanding. The model is trained to find patterns in sentences, correlations between the different words used in those sentences, and even predict the word that is likely to come next.

Is python a lambda?

What is Lambda Function in Python? Lambda Function, also referred to as 'Anonymous function' is same as a regular python function but can be defined without a name. While normal functions are defined using the def keyword, anonymous functions are defined using the lambda keyword.

Which language is best for lambda?

It is well known that Node and Python are the leading languages for Lambda, but it's interesting to dig even deeper and get the exact numbers for each version used. Node 8.10 is the clear winner with 51.7 percent of functions using it.

What is lambda and how it works?

You organize your code into Lambda functions. Lambda runs your function only when needed and scales automatically, from a few requests per day to thousands per second. You pay only for the compute time that you consume—there is no charge when your code is not running.


2 Answers

A lambda language, in simple terms, is a language that allows passing a function to another function, where the function is treated as any other variable. Also, you should be able to define this function to be passed anonymously (or inline). PHP 5.3 added support for lambda functions. Was JavaScript the first mainstream language? Lisp has been widely used in educational settings before JavaScript and also in customizing our beloved Emacs http://www.gnu.org/software/emacs/manual/html_node/eintr/

Here's an example

function applyOperation(a, b, operation) {   return operation(a,b); }  function add(a,b) { return a+ b; } function subtract(a,b) {return a - b;}  // Can be called like applyOperation(1,2, add); applyOperation(4,5, subtract); // Anonymous inline function applyOperation(4,7, function(a,b) {return a * b}) 

How is it different from C? In C, you can pass pointer to functions, but you can't define it inline anonymously.

In Java (before version 8), to achieve the same effect, you must pass an object that implements an interface, which actually can be defined anonymously inline.

like image 66
Juan Mendes Avatar answered Sep 30 '22 21:09

Juan Mendes


I've never heard anyone use the term "lambda language," and the only plausible definitions I can think of would exclude JavaScript as "the first."

That said, I suspect he may mean either:

  • Functional languages: a class of languages in which computation is (or can be) modeled as a stateless composition of (possibly higher-order) functions. LISP, Scheme, ML, Haskell, etc. are frequently ascribed to this class, although several of these are more properly mixed paradigm or "functional optional" languages. Javascript arguably contains the necessary features to make a "functional style" of programming possible.
  • Languages which allow the creation of anonymous functions (using the function syntax in JavaScript; this is written lambda in many languages, hence possibly "lambda languages."

Both usages are derived from the use of the greek letter lambda to denote function abstraction in the lambda calculus, the model of computation devised by Alonzo Church and upon which functional programming is based.

Edit: looked at Google Books result---"first to go mainstream"; well, that's arguable. I'd put forward that LISP was at one point at least reasonably mainstream. It's a fair point though, JavaScript's semantics are directly inspired by Scheme and it certainly reached a larger audience than any other language that can make similar claims.

like image 39
Derrick Turk Avatar answered Sep 30 '22 21:09

Derrick Turk