1

I saw two concepts

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

I'm confused?

HamedFathi
  • 3,667
  • 5
  • 32
  • 72
  • 3
    They are not the same. First-class means a function *is* a value. Anonymous means a function can be created without a name. They are usually hand-in-hand, though (because a function as a value can be bound to different names). – user2864740 Jan 07 '14 at 21:12

2 Answers2

3

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.

Marcin
  • 48,559
  • 18
  • 128
  • 201
  • Do we need Delegates for having anonymous functions ? like C# - C# have delegates so have anonymous functions but java does not have delegates and anonymous functions - Does Delegates are not necessary for languages ​​such as Java,Groovy,Scala,...? – HamedFathi Jan 07 '14 at 21:31
  • @user3166171 I don't know what C# delegates are. They are not necessary to anonymous functions. – Marcin Jan 07 '14 at 21:45
0

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.

munificent
  • 11,946
  • 2
  • 38
  • 55