(One intermediate revision by one other user not shown)
Line 1:
'''[[Boldy James|Bold]]'''{{Short description|Programming language feature}}
== '''In [[computer science]], a [[programming language]] is said to have '''first-class functions''' if it treats [[Functionfunction (programming)|functionsfunction]]s as [[Firstfirst-class citizen|first-class citizens]]s. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.<ref>{{cite book|first1=Harold|last1=Abelson|first1authorlink1=Harold Abelson|urlfirst2=https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-12.html#%_sec_1.3Gerald Jay|last2=Sussman|authorlink2=Gerald Jay Sussman|title=Structure and Interpretation of Computer Programs|last2at=Sussman[https://archive.org/details/structureinterpr00abel/page/ |first2=GeraldFormulating JayAbstractions with Higher-Order Procedures]|publisher=MIT Press|year=1984|isbn=0-262-01077-1|aturl=[https://archivemitpress.orgmit.edu/detailssites/structureinterpr00abeldefault/pagefiles/ Formulating Abstractions with Highersicp/full-Order Procedures] text/book/book-Z-H-12.html#%_sec_1.3|access-date=2021-09-27|archive-date=2021-09-21|archive-url=https://web.archive.org/web/20210921155625/https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-12.html#%_sec_1.3 |archive-date=2021-09-21 |url-status=dead |authorlink1=Harold Abelson |authorlink2=Gerald Jay Sussman}}</ref> Some programming language theorists require support for [[Anonymousanonymous function|anonymous functions]]s (function literals) as well.<ref name="test">[http://www.worldcat.org/oclc/222529448 Programming language pragmatics], by Michael Lee Scott, section 11.2 "Functional Programming".</ref> In languages with first-class functions, the [[Namename (computer science)|names]] of functions do not have any special status; they are treated like ordinary [[Variablevariable (computer science)|variablesvariable]]s with a [[function type]].<ref>{{cite journal |title=The Implementation of Lua 5.0 |author1=Roberto Ierusalimschy |author1-link=Roberto Ierusalimschy |author2=Luiz Henrique de Figueiredo |author3=Waldemar Celes |date=2005 |title=The Implementation of Lua 5.0 |journal=Journal of Universal Computer Science |volume=11 |issue=7 |pages=1159–1176 |doi=10.3217/jucs-011-07-1159 |doi-access=free |volume=11 |issue=7 |date=2005 |pages=1159–1176}}</ref> The term was coined by [[Christopher Strachey]] in the context of "functions as first-class citizens" in the mid-1960s.<ref name="strachey">{{cite journal|last1=Burstall |first1=Rod |last2=Strachey |first2=Christopher |date=2000 |title=Understanding Programming Languages |url=http://www.cs.cmu.edu/~crary/819-f09/Strachey67.pdf |url-status=bot: unknown |journal=[[Higher-Order and Symbolic Computation]] |date=2000 |volume=13 |issue=52 |pages=11–49 |doi=10.1023/A:1010052305354 |s2cid=1989590 |url=http://www.cs.cmu.edu/~crary/819-f09/Strachey67.pdf |url-status=bot: unknown |archiveurl=https://web.archive.org/web/20100216060948/http://www.cs.cmu.edu/~crary/819-f09/Strachey67.pdf |archivedate=February 16, 2010 }} (also on 2010-02-16</ref>
<references><ref>{{Cite web |title= |url=}}</ref></references>''' ==
First-class functions are a necessity for the [[functional programming]] style, in which the use of [[higher-order function]]s is a standard practice. A simple example of a higher-ordered function is the ''[[map (higher-order function)|map]]'' function, which takes, as its arguments, a function and a list, and returns the list formed by applying the function to each member of the list. For a language to support ''map'', it must support passing a function as an argument.