Anonymous function: Difference between revisions

Content deleted Content added
Meownium (talk | contribs)
m Revise Ada support, citate
Uses: Tried to cover the usage pros and cons. Simplified by removed the weird meaningless phrase "more-generic". Qualified the "more efficient" with in dynamic programming language
Line 14:
Anonymous functions can be used for containing functionality that need not be named and possibly for short-term use. Some notable examples include [[Closure (computer science)|closures]] and [[currying]].
 
The 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. SomeAnonymous programmersfunctions useoften anonymousprovide a briefer notation than defining named functions. toIn encapsulatelanguages specificthat do not permit the definition of named functions in local scopes, non-reusableanonymous codefunctions withoutmay litteringprovide encapsulation via localized scope, however the code within athe lotbody of littlesuch oneanonymous function may not be re-lineusable, normalor amenable to separate testing. Short/simple anonymous functions used in expressions may be easier to read and understand than separately defined named functions, though without a [[Naming_convention_(programming)|descriptive name]] they may be more difficult to understand.
 
In some programming languages, anonymous functions are commonly implemented for very specific purposes such as binding events to callbacks or instantiating the function for particular values, which may be more efficient in a [[Dynamic programming language]], more readable, and less error-prone than calling a more-generic named function.
 
The following examples are written in Python 3.