什么是Lambda? [英] What is a Lambda?

查看:73
本文介绍了什么是Lambda?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以很好地描述Lambda是什么吗?我们为它们添加了标签,它们位于C#问题的机密上,但是我还没有找到关于它们的含义的良好定义和解释.

Could someone provide a good description of what a Lambda is? We have a tag for them and they're on the secrets of C# question, but I have yet to find a good definition and explanation of what they are in the first place.

推荐答案

闭包,lambda和匿名函数不一定是同一件事.

Closures, lambdas, and anonymous functions are not necessarily the same thing.

匿名函数是没有(或至少不需要)自己名称的任何函数.

An anonymous function is any function that doesn't have (or, at least, need) its own name.

闭包是一种函数,即使声明了 后,它也可以访问声明时处于其词法范围内的变量.匿名函数不必一定是闭包,但是在大多数语言中它们都是闭包的,而当不是闭包时,它们的用处就会减少.

A closure is a function that can access variables that were in its lexical scope when it was declared, even after they have fallen out of scope. Anonymous functions do not necessarily have to be closures, but they are in most languages and become rather less useful when they aren't.

就计算机科学而言,lambda的定义不太好.许多语言甚至不使用该术语.相反,他们只会称其为闭包或匿名函数或发明自己的术语.在LISP中,lambda只是一个匿名函数.在Python中,lambda是一个匿名函数,专门限于单个表达式.还有更多,您需要一个命名函数. Lambda是两种语言的闭包.

A lambda is.. not quite so well defined as far as computer science goes. A lot of languages don't even use the term; instead they will just call them closures or anon functions or invent their own terminology. In LISP, a lambda is just an anonymous function. In Python, a lambda is an anonymous function specifically limited to a single expression; anything more, and you need a named function. Lambdas are closures in both languages.

这篇关于什么是Lambda?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆