Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Nested function
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Languages == Notable languages supporting nested functions include: *[[ALGOL]]-based languages such as [[ALGOL 68]], [[Simula]], [[Pascal (programming language)|Pascal]], [[Modula-2]], [[Modula-3]], [[Oberon (programming language)|Oberon]], [[PL/I]], [[Seed7]] and [[Ada (programming language)|Ada]] *Modern versions of [[Lisp (programming language)|Lisp]] (with lexical scope) such as [[Scheme (programming language)|Scheme]], and [[Common Lisp]] *[[ECMAScript]] ([[JavaScript]] and [[ActionScript]]) *[[Dart (programming language)|Dart]]<ref>{{Cite web|url=https://dart.dev/guides/language/language-tour#lexical-scope|title=A tour of the Dart language}}</ref> *[[Kotlin (programming language)|Kotlin]] (local functions<ref>{{Cite web|url=https://kotlinlang.org/docs/functions.html#local-functions|title = Functions | Kotlin}}</ref>) *[[Rust (programming language)|Rust]] *[[Scala (programming language)|Scala]] (nested functions<ref>{{Cite web|url=https://docs.scala-lang.org/tour/nested-functions.html|title=Nested Methods}}</ref>) *Various degrees of support in scripting languages such as [[Ruby (programming language)|Ruby]], [[Python (programming language)|Python]], [[Lua (programming language)|Lua]], [[PHP]] and [[Perl]] *[[GNU Compiler Collection|GCC]] supports nested functions in C, as a language extension.<ref>{{cite web|url=https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html|title=Nested Functions β Using the GNU Compiler Collection (GCC)|accessdate=2007-01-06|publisher=GNU Project}}</ref> *[[C Sharp (programming language)|C#]], starting with C# 7.0 *The [[D (programming language)|D]] language, a C-related language with nested functions. *[[Fortran]], starting with [[Fortran#Fortran 90|Fortran-90]], supports ''a single level'' of nested (''CONTAINed'') subroutines and functions. *[[MATLAB]] (full support) *[[Wolfram Language]] *[[Go (programming language)| Golang]] (Function closures<ref>{{Cite web|url=https://go.dev/tour/moretypes/25|title=A tour of Go}}</ref>) === Functional languages === In most [[functional programming]] languages, such as Scheme, nested functions are a [[Programming idiom|common way]] of implementing [[algorithm]]s with loops in them. A simple ([[tail recursion|tail]]) [[recursion|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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)