function is the only alternative: the nested function is declared not as usual function, but by reference, as a local variable. To use local variables in the anonymous function, use closure. Languages Well known languages supporting lexically nested functions include: ALGOL-based languages such as ALGOL 68, Simula, Pascal, Modula-2, Modula-3, Oberon, Seed7 and Ada Modern versions of Lisp (with lexical scope) such as Scheme, and Common Lisp ECMAScript (JavaScript and ActionScript) Dart Kotlin (local functions) Scala (nested functions) Various degrees of support in scripting languages such as Ruby, Python, Lua, PHP and Perl GCC supports nested functions in C, as a language extension. C#, starting with C# 7.0 The D language, a C-related language with nested functions. Fortran, starting with Fortran-90, supports a single level of nested (CONTAINed) subroutines and functions. MATLAB (full support) Wolfram Language Functional languages In most functional programming languages, such as Scheme, nested functions are a common way of implementing algorithms with loops in them. A simple (tail) recursive inner function is created, which behaves as the algorithm's main loop, while the outer function performs startup actions that only need to be done once. In more complex cases, a number of mutually recursive functions may be created as inner functions. Some languages without direct support Certain languages do not have straightforward syntactic and semantic support to implement nested functions. Nevertheless, for some of them the idea of nested functions can be simulated with some degree of difficulty through the use of other language constructs. The following languages can approximate nested functions through the respective strategies: C++ before C++11: allows definition of classes within classes, providing the ability to use class methods in a way similar to nested functions in one level (see Function object in C++). since C++11: by using lambda expressions as the quicksort example above. Eiffel explicitly disallows nesting of routines. This is to keep the language simple, and also allows the convention of using a special variable, Result, to denote the result of a (value-returning) function. Visual Basic, by using anonymous methods or lambda expressions. Java, by using lambda expressions (see Anonymous functions in Java) (since Java 8) or through a workaround that consists in an anonymous class containing a single method. A named class declared local to a method may also be used. Implementation Implementation of nested functions can be more involved than it may appear, as a reference to a nested