Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Scope (computer science)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
=== Lexical scope vs. dynamic scope === A fundamental distinction in scope is what "part of a program" means. In languages with '''lexical scope''' (also called '''static scope'''), name resolution depends on the location in the source code and the ''lexical context'' (also called ''static context''), which is defined by where the named variable or function is defined. In contrast, in languages with '''dynamic scope,''' the name resolution depends upon the [[program state]] when the name is encountered which is determined by the ''execution context'' (also called ''runtime context'', ''calling context'' or ''dynamic context''). In practice, with lexical scope a name is resolved by searching the local lexical context, then if that fails, by searching the outer lexical context, and so on; whereas with dynamic scope, a name is resolved by searching the local execution context, then if that fails, by searching the outer execution context, and so on, progressing up the call stack.<ref name=Borning /> Most modern languages use lexical scope for variables and functions, though dynamic scope is used in some languages, notably some dialects of Lisp, some "scripting" languages, and some [[template language]]s.{{efn|1=For example, the [[Jinja (template engine)|Jinja]] template engine for Python by default uses both lexical scope (for imports) and dynamic scope (for includes), and allows behavior to be specified with keywords; see [http://jinja.pocoo.org/docs/templates/#import-context-behavior Import Context Behavior].}} Perl 5 offers both lexical and dynamic scope. Even in lexically scoped languages, scope for [[Closure (computer science)|closures]] can be confusing to the uninitiated,{{citation needed|date=March 2022}} as these depend on the lexical context where the closure is defined, not where it is called. Lexical resolution can be determined at [[compile time]], and is also known as ''early binding'', while dynamic resolution can in general only be determined at [[Run time (program lifecycle phase)|run time]], and thus is known as ''late binding''.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Scope (computer science)
(section)
Add topic