1. 程式人生 > >First-class function 頭等函式

First-class function 頭等函式

Python 介紹說 Python has first class functions,記得lua也這麼說過,那麼頭等函式是什麼意思是呢?

摘自first class functions wiki百科

In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. Specifically, 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.


在電腦科學中,如果一門程式語言把函式看做頭等公民就可以這門語言支援頭等函式。具體也就是說,函式能像引數那樣被傳遞到另一個函式、從另一個函式那像值一樣被返回出來、函式可以賦值給變數或者存在資料結構中。


頭等公民

摘自first-class citizens wiki百科

In programming language design, a first-class citizen (also objectentity, or value) in a given programming language

 is an entity which supports all the operations generally available to other entities. These operations typically include being passed as a parameter, returned from a function, and assigned to a variable.