First-class citizen

https://en.wikipedia.org/wiki/Functional_programming

https://en.wikipedia.org/wiki/First-class_citizen

In programming language design, a first-class citizen (also typeobjectentity, 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 an argument, returned from a function, modified, and assigned to a variable.[1]

First-class and higher-order functions[edit]

Main articles: First-class function and Higher-order function

Higher-order functions are functions that can either take other functions as arguments or return them as results. In calculus, an example of a higher-order function is the differential operator ddx, which returns the derivative of a function f.

Higher-order functions are closely related to first-class functions in that higher-order functions and first-class functions both allow functions as arguments and results of other functions. The distinction between the two is subtle: "higher-order" describes a mathematical concept of functions that operate on other functions, while "first-class" is a computer science term that describes programming language entities that have no restriction on their use (thus first-class functions can appear anywhere in the program that other first-class entities like numbers can, including as arguments to other functions and as their return values).

Higher-order functions enable partial application or currying, a technique in which a function is applied to its arguments one at a time, with each application returning a new function that accepts the next argument. This allows one to succinctly express, for example, the successor function as the addition operator partially applied to the natural number one.

Many programming languages support passing and returning function values, which can be applied to arguments. Whether this suffices to call function values first-class is disputed.

Some authors require it be possible to create new functions at runtime to call them ‘first-class‘. As a result, functions in C are not first-class objects; instead, they are sometimes called second-class objects, because they can still be manipulated in most of the above fashions (via function pointers).

In Smalltalk, functions (methods) are first-class objects, just like Smalltalk classes. Since Smalltalk operators (+, -, etc.) are methods, they are also first-class objects.

时间: 2024-11-09 02:09:48

First-class citizen的相关文章

Python面向对象程序设计第一弹

类和对象: 定义类: class 类名: 属性 方法 定义类的对象: 类的对象名=类名() 类的属性:分为公有和私有,类似于c++的private和public,私有变量名前面添加__ 构造函数:在创建类的对象的时候,对类进行初始化的函数.(它的功能远不止赋值这么简单,思维不要被局限了) 形式:def __init__(self,其他参数) 语句块 关于其中的self,self代表的是类的实例,代表当前对象的地址.(按照我的逻辑解释,因为类里面的函数作用在类的对象上,那么对象就是自身,用self

词组习语3057组

superword是一个Java实现的英文单词分析软件,主要研究英语单词音近形似转化规律.前缀后缀规律.词之间的相似性规律等等. 1 Anointing of the Sick British English 2 Civvy Street Clerk of the Closet 3 I mean I must say 4 I suppose so I will thank you to do something 5 Incoming mail server Lithium battery 6 M

【Codeforces163E】e-Government AC自动机fail树 + DFS序 + 树状数组

E. e-Government time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automa

Getting started with TypeScript and Sublime Text -- 摘自https://cmatskas.com/getting-started-with-typescript-and-sublime-text/

Getting started with TypeScript and Sublime Text 04 March 2015  18 Comments  Posted in JavaScript, Open Source, TypeScript, Sublime Text UPDATED: This post has been rewritten around the official TypeScript plugin Typescript is awesome, period. TypeSc

How To Easily Call WCF Services Properly z

Please note: this article has been superceded by the documentation for the ChannelAdam WCF Library. Background In my previous article, How To Call WCF Services Properly, I researched and highlighted the typical problems with using WCF clients (such a

用Kotlin语言重新编写Plaid APP:经验教训(II)

原文标题:Converting Plaid to Kotlin: Lessons learned (Part 2) 原文链接:http://antonioleiva.com/plaid-kotlin-2/ 原文作者:Antonio Leiva(http://antonioleiva.com/about/) 原文发布:2015-11-17 我们在第一部分中所见的各种显著地改进,要归功于在Activity中使用了Kotlin语言.但是,由于主要是重载方法做些事情,仍然免不了一些公式化代码,所以这种类

hdu5432 二分

Pyramid Split Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 104    Accepted Submission(s): 50 Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which

hdu 5432 Pyramid Split(二分搜索)

Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which have square undersides,let's call them pyramids. Anyone of them can be defined by the square's length and the height,called them width and height. To ea

URAL1961:Cantonese Dialect

After some thought on where to spend a holiday Vova decided to travel around South China and visit Guangzhou, Shenzhen, Macau and Hong Kong. Vova heard that South China speaks the Cantonese dialect of the Chinese language. So before setting off he le