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
Scope (computer science)
(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!
=== Expression scope === The scope of a name binding is an [[Expression (computer science)|expression]], which is known as '''expression scope'''. Expression scope is available in many languages, especially [[Functional programming|functional]] languages which offer a feature called ''[[let expression]]s'' allowing a declaration's scope to be a single expression. This is convenient if, for example, an intermediate value is needed for a computation. For example, in [[Standard ML]], if <code>f()</code> returns <code>12</code>, then <code>'''let val''' x = f() '''in''' x * x '''end'''</code> is an expression that evaluates to <code>144</code>, using a temporary variable named <code>x</code> to avoid calling <code>f()</code> twice. Some languages with block scope approximate this functionality by offering syntax for a block to be embedded into an expression; for example, the aforementioned Standard ML expression could be written in [[Perl]] as <syntaxhighlight lang="perl" inline>do { my $x = f(); $x * $x }</syntaxhighlight>, or in [[GNU Compiler Collection|GNU C]] as <syntaxhighlight lang="c" inline>({ int x = f(); x * x; })</syntaxhighlight>. In Python, auxiliary variables in generator expressions and list comprehensions (in Python 3) have expression scope. In C, variable names in a [[function prototype]] have expression scope, known in this context as '''function protocol scope'''. As the variable names in the prototype are not referred to (they may be different in the actual definition)—they are just dummies—these are often omitted, though they may be used for generating documentation, for instance.
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)