Friday, October 12, 2018

first class

現在一些比較新的 programming language 有時候都會在語言裡加入新的 first class element 。對我來講,這個詞彙 first class ,總是讓我覺得有「理解的困難」,到底什麼才叫 first class 呢?

有一回,我終於在 SICP Distilled 看到定義了。

In general, programming languages impose restrictions on the ways in which computational elements can be manipulated. Elements with the fewest restrictions are said to have first-class status, an idea originally due to Christopher Strachey
Some of the “rights and privileges” of first-class elements are that they may be:
  • Named by variables
  • Passed as arguments to functions
  • Returned as the results of functions
  • Included in data structures
Lisps, unlike other common programming languages, awards functions full first-class status. This poses challenges for efficient implementation, but the resulting gain in expressive power is enormous.