什麼是 Lambda? (What is a Lambda?)


問題描述

什麼是 Lambda? (What is a Lambda?)

有人能很好地描述什麼是 Lambda 嗎?我們為它們提供了一個標籤,它們在 C# 問題的秘密上,但我還沒有找到一個好的定義和解釋它們是什麼。


參考解法

方法 1:

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.

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.

方法 2:

Also called closures or anonymous functions.. I found the best description here. Basically, inline block of code that can be passed as an argument to a function.

方法 3:

"Lambda" refers to the Lambda Calculus or to a specific lambda expression. Lambda calculus is basically a branch of logic and mathematics that deals with functions, and is the basis of functional programming languages.

~ William Riley‑Land

方法 4:

It's just an anonymous function declared inline, most typically assigned to a delegate when you don't want to write a full‑fledged function.

In languages like lisp/scheme, they're often passed around quite liberally as function parameters, but the idiom in C# typically finds lambdas used only for lazy evaluation of functions, as in linq, or for making event‑handling code a bit terser.

方法 5:

There's not really such a thing as 'a lambda' in programming. It depends on the language, etc.

In short, normally a language that 'has lambdas' uses the term for anonymous functions or, in some cases, closures. Like so, in Ruby:

f = lambda { return "this is a function with no name" }
puts f.call

(by FredEeveeGulzar NazimwprlJasonTruerfunduk)

參考文件

  1. What is a Lambda? (CC BY‑SA 2.5/3.0/4.0)

#terminology #lambda #computer-science #language-agnostic






相關問題

抽象 ViewModel 在被繼承時是否被視為模型? (Is an abstract ViewModel considered a Model when it is inherited?)

什麼是 Lambda? (What is a Lambda?)

具體確定項目順序的排序的正確術語是什麼? (What is the proper term for an ordering where the order of items is concretely determined?)

在 Ruby 中,“接收者”指的是什麼? (In Ruby what does the "receiver" refer to?)

錯誤跟踪和問題跟踪系統有什麼區別? (What's the difference between a bug tracking and an issue tracking system?)

為什麼術語 API 和 SDK 似乎可以互換使用? (Why do the terms API and an SDK seem to be used interchangeably?)

Java 中的對等類是什麼? (What is a peer class in Java?)

模擬和模擬有什麼區別? (what is the difference between Emulate and Simulate?)

協議術語:消息與數據包 (Protocol Terminology: Message versus Packet)

表示“目錄”或“文件”的詞是什麼? (What is the word that means "directory" or "file"?)

C ++中復合語句和塊之間的區別? (Difference between a compound statement and a block in C++?)

gnu八度中gnu的含義? (Meaning of gnu in gnu octave?)







留言討論