-6
$\begingroup$

I mean, is there an antonym for "first-class function"?

$\endgroup$
  • 1
    $\begingroup$ If you wanted more than what's on wikipedia it would've been helpful to provide more context. $\endgroup$ – Huck Bennett Aug 30 '11 at 20:58
  • $\begingroup$ @Huck Bennett If you read the wikipedia article, you will only see it saying that, in imperative languages, the functions are "second-class citizens". But it's not clear if every "non-first-class function" is a "second-class function". Also, in Ohad's answer, he tells about "first-order functions", which is new for me, and there isn't an article on Wikipedia about that. So maybe the answers here are more interesting then Wikipedia. And it's a simple theoretical question, I really can't see how could I provide more context. $\endgroup$ – Tom Brito Aug 31 '11 at 14:01
12
$\begingroup$

First, the property "having first-class functions" is a property of a programming language, not of particular functions in it. Either your language allows for functions to be passed around and created at will, or it doesn't.

Functions that accept or return other functions as arguments are called higher-order functions. (The terminology comes from logic.) Functions that don't are called first-order functions. Perhaps this latter notion is what you wanted.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ I really don't see why you, in theory, couldn't have programming languages where some functions where objects while others, for one reason or another, weren't. $\endgroup$ – Tilo Wiklund Sep 1 '11 at 8:07
  • 1
    $\begingroup$ You can, but then the property 'has first class functions' doesn't hold for your language. For example, in Ada you can pass functions that don't require a closure around. So you have something resembling higher-order functions, but the language doesn't have first class functions (for other reasons too). $\endgroup$ – Ohad Kammar Sep 1 '11 at 9:04
  • 1
    $\begingroup$ My point is that indeed some languages have that property. But I'm not familiar with specialised terminology to them. $\endgroup$ – Ohad Kammar Sep 1 '11 at 9:22
4
$\begingroup$

"First-class" here is roughly the informal use of the phrase meaning "having all rights and privileges", give or take. The alternative would be "second-class", as in the phrase "second-class citizen", but that seems to be less frequently used in this context.

It is, as Ohad says, a feature of a language which entities (functions or otherwise) it treats as "first-class", and it's also not necessarily a clear-cut distinction. Typically a first-class entity would be something tangible that can be created and used as a value at run time, without significant obstacles compared to being defined at compile time. In the case of functions, this usually means allowing higher-order and anonymous functions. A function that is not higher-order is first-order. Functions that are not anonymous don't really have a general term that I know of. But first-order functions with names can still be first-class if the language allows it.

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ I also use 'second-class citizen'. $\endgroup$ – gasche Aug 30 '11 at 19:13
  • $\begingroup$ Sorry, if "first-class functions" and "higher-order functions" are the same, and "first-order" is the opposite of "higher-order", how first-order functions can be first-class? $\endgroup$ – Tom Brito Aug 30 '11 at 20:09
  • 2
    $\begingroup$ @Tom The answer is not saying that "first-class function" are the same as "higher-order functions". The answer says that when functions are treated as first-class entities in a programming language, then that programming language usually allows higher-order (and other kinds) of functions. In other words, red is a color, green is the opposite of red, green is still a color. $\endgroup$ – Artem Kaznatcheev Aug 30 '11 at 20:18
  • 1
    $\begingroup$ @Tom Brito: They're not the same. A language with first-class functions is one that lets them be manipulated directly. It's about what you can do with a function, not the function itself. In a language with first-class functions, plain first-order functions can still be passed around as arguments to higher-order functions. Note also these terms are entirely unrelated, and the fact that both use the word "first" doesn't really mean anything. $\endgroup$ – C. A. McCann Aug 30 '11 at 20:31
  • 2
    $\begingroup$ @Tom Brito: No, it's the same term as applied to logic, as Ohad's answer mentioned. Read the article on first-order logic if you want a better understanding of the term, and it's not too hard to see the connection to programming languages. The redirect is there because first-order functions are a trivial concept interesting only by contrast of not being higher-order. $\endgroup$ – C. A. McCann Aug 31 '11 at 14:42
2
$\begingroup$

In formal set theory a "mapping" which isn't a function (in the formal sense) is usually called a definable mapping. The reason this might be a meaningful term to import is that these are, in some sense, the things which behave like functions in the meta theory/language while not being, themselves, objects in the theory studied (the object language).

Alternatively borrowing terms from category theory one might want to call them external functions (since they are not "elements" of the internal Hom-objects, i.e. the exponential objects). (Kept this for the comments to make sense).

Borrowing the distinction from category between external and internal Hom-sets (that is to say collections of arrows of a category and exponential objects of a category) one might want to call "non-first class functions" external functions.

I doubt any of these are in common use, but they might at least be suggestive :)

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ I think the typical use of Category Theory in this case would simply regard functions as the arrows of the category, and define "having first-class functions" as "having exponential objects". $\endgroup$ – C. A. McCann Aug 31 '11 at 14:34
  • $\begingroup$ I agree, what I meant was that one could import the internal/external distinction of Hom-sets (the Hom-functor and the exponential objects) to internal vs. external functions. $\endgroup$ – Tilo Wiklund Aug 31 '11 at 14:44
  • $\begingroup$ Oh, I see. I think I misread at first. That's actually a reasonably tidy choice of terminology now that I think about it. $\endgroup$ – C. A. McCann Aug 31 '11 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.