Anonymous function: Difference between revisions

Content deleted Content added
Bigtrick (talk | contribs)
m fixed some bad grammar.
Added examples for python & PHP
Line 2:
 
Some [[object-oriented]] programming languages have [[anonymous class]]es, which are a similar concept. [[Java (programming language)|Java]] is such a language.
 
==Examples==
Numerous languages support anonymous functions, or something similar.
 
===Python===
<source lang="python">
foo = lambda x: x*x
print foo(10)
</source>
 
===PHP===
PHP doesn't have true anonymous functions because the only way to reference functions is by name. The closest PHP is shown in the following.
<source lang="php">
$foo = create_function("$x", "return $x*$x;");
echo $foo(10);
</source>
 
{{compu-prog-stub}}