lambda表达式、匿名函数

本文介绍了lambda表达式作为函数式编程中的一种匿名函数形式,在计算机编程中的应用。它探讨了lambda表达式的起源及其在现代编程语言中的作用,包括作为临时函数传递给高阶函数的情况以及在构造返回函数的高阶函数中的用途。

lambda表达式是函数式编程中的匿名函数语法规范。

 

In computer programming, an anonymous function (function literallambda abstraction, or lambda expression) is a function definition that is not bound to an identifier. Anonymous functions are often:[1]

  • arguments being passed to higher-order functions, or
  • used for constructing the result of a higher-order function that needs to return a function.

If the function is only used once, or a limited number of times, an anonymous function may be syntactically lighter than using a named function. Anonymous functions are ubiquitous in functional programming languages and other languages with first-class functions, where they fulfill the same role for the function type as literals do for other data types.

Anonymous functions originate in the work of Alonzo Church in his invention of the lambda calculus in 1936, before electronic computers, in which all functions are anonymous.[2]

 

 

Anonymous functions can be used for containing functionality that need not be named and possibly for short-term use. Some notable examples include closures and currying.

Use of anonymous functions is a matter of style. Using them is never the only way to solve a problem; each anonymous function could instead be defined as a named function and called by name. Some programmers use anonymous functions to encapsulate specific, non-reusable code without littering the code with a lot of little one-line normal functions.

 

https://en.wikipedia.org/wiki/Anonymous_function#C.23_lambda_expressions

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值