Anonymous Function

In a programming language, an unnamed function object (also: "function literal").

Example (in PseudoCode):

"lambda(x,y){ x>y }" is an anonymous function object representing the function that tells whether its first argument is greater than its second argument.

This lets you write (e.g.)

sort(lambda(x,y){ x>y }, [5,7,3,4,9,5,4])

instead of

def compfunc(x,y) {
x>y
}
sort(compfunc,[5,7,3,4,9,5,4])

Analogously, "42" is an anonymous number object (or "number literal") representing the number 42, which lets you write (e.g.)

set_age(42)

instead of

def value := 42
set_age(value)

(for the last code snippet, imagine that this was written in a programming language that does not let you use numbers directly, but always requires you to give them a name first using "def := ")

The syntax of anonymous functions depends on the programming language being used:

Shouldn't this be simply called an 'unnamed function'? -- MarkJanssen

Sometimes it is. In every technical field, science or craft, some things get multiple names.


See also LambdaExpression