Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Function Literal / Anonymous Function

Part of FunctionLiteralsCategory

Description

Function Literals enable embedding anonymous functions directly into expressions.

Example

import std.stdio;

int function(char c) fp;

void main() { 
  fp = function int(char c) { 
    return 6;
  }; //note the semi-colon at the end 

  writefln(fp('A')); // Prints 6
}

More Information

For more details, see the D Specification.

Source

Based on http://www.prowiki.org/wiki4d/wiki.cgi?DWiki/FunctionLiterals which was copied from http://dlanguage.netunify.com/11 (dead link).