What is different between First-class function and Anonymous function?

1k views Asked by At

I saw two concepts

It seems that these two concepts are the same? (lambda)

I'm confused?

2

There are 2 answers

2
Marcin On BEST ANSWER

A first class function is one which is reified - i.e. it can be manipulated as part of the language, can be passed to other functions, be the value of a variable.

An anonymous function is just one which does not have a name (or does not have a "function" name, if functions and variables occupy separate namespaces).

It would be moderately difficult to design a language with anonymous, non-first-class functions, but the two concepts are sufficiently distinct that you at least kinda-sorta could. Equally, you definitely could have a language with first class functions, but no anonymous functions. These languages are rare, because there's little point in such a design.

0
munificent On

Marcin has the right answer. To give some examples: C and C# 1.0 both have first-class functions, but do not have anonymous functions. In both cases, you can only explicitly declare named functions, but once you have, you can get references to them and store them in variables.