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

查看:32
本文介绍了什么是 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天全站免登陆