encyclopegia.org

Non-local variable

In programming language theory, a non-local variable is a variable that is not defined in the local scope. While the term can refer to global variables, it is primarily used in the context of nested and anonymous functions where some variables can be in neither the local nor the global scope. In Lua they are called the upvalues of the function. == Examples == === Nested functions === In the Python 3 example that follows there is a nested function inner defined in the scope of another function outer . The variable x is local to outer , but non-local to inner (nor is it global): from typing import Callable def outer() -> Callable[[], None]: x: int = 1 def inner() -> None: nonlocal x x += 1 print(x) return inner In JavaScript, the locality of a variable is determined by the closest var statement for this variable. In the following example, x is local to outer as it contains a var x statement, while inner doesn't. Therefore, x is non-local to inner : function outer() { var x = 1; function inner() { x += 1; console.log(x); } return inner; } === Anonymous functions === In the Haskell example that follows the variable c is non-local in the anonymous function \x -> x + c : outer = let c = 1 in map (\x -> x + c) [1, 2, 3, 4, 5]

In programming language theory, a non-local variable is a variable that is not defined in the local scope. While the term can refer to global variables, it is primarily used in the context of nested and anonymous functions where some variables can be in neither the local nor the global scope. In Lua they are called the upvalues of the function. from typing import Callable def outer() -> Callable[[], None]: x: int = 1 def inner() -> None: nonlocal x x += 1 print(x) return inner In JavaScript, the locality of a variable is determined by the closest var statement for this variable. In the following example, x is local to outer as it contains a var x statement, while inner doesn't. Therefore, x is non-local to inner : function outer() { var x = 1; function inner() { x += 1; console.log(x); } return inner; } outer = let c = 1 in map (\x -> x + c) [1, 2, 3, 4, 5] ==Notes==

References

  1. 27.3.3 – Upvalues · retrieved 2026-11-18 · rev 1310963400
    Cite this reference

    MLA "27.3.3 – Upvalues." Programming in Lua (first edition) , " 27. 2026-11-18. http://www.lua.org/pil/contents.html. Accessed 24 November 2026.

    Chicago "27.3.3 – Upvalues." Programming in Lua (first edition) , " 27. 2026-11-18. http://www.lua.org/pil/contents.html.

    APA Programming in Lua (first edition) , " 27. (2026). 27.3.3 – Upvalues. Retrieved November 24, 2026, from http://www.lua.org/pil/contents.html

Cite this article

MLA

"Non-local variable." encyclopegia.org, 2025, https://encyclopegia.org/wiki/non-local-variable. Accessed 24 November 2026.

Chicago

"Non-local variable." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/non-local-variable.

APA

encyclopegia.org. (2025). Non-local variable. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/non-local-variable

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

SX Phoenicis variable

stub · references available

1991 Spanish local elections

stub · references available

Non-Aligned Movement

stub · references available

variable cost

stub · references available

random variable

stub · references available

Laingsburg Local Municipality

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1310963400 · 0.5 · snapshot enwiki-001310963400

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.