Talk:Scope (computer science)

message: In my experience, the concept of "scope" pertains exclusively to identifiers and declarations; and indeed, most of the article is only about scope insofar as it pertains to identifiers and declarations. (Though, maybe that's not saying much: most of the article is only about variable-names, and obviously lots of other things can also have scope.) The lead text, however, seems to downplay that aspect of scope; the word "identifier" hardly appears, and instead we get text about "values and expressions", and about how scopes can "contain statements and/or expressions which define an executable algorithm or part thereof" and can "nest or be nested" (which I think are really supposed to be statements about blocks, in block-structured languages, rather than about scopes per se).
So, I think the lead text should be completely rewritten.
Before I proceed — does anyone disagree?
—RuakhTALK 04:36, 1 February 2012 (UTC)
replies: text: —RuakhTALK 15:20, 2 February 2012 (UTC)
thread_title: 
Misleading lead text.


message: So I came here following some link trying to find out what exactly the difference between Lexical/Dynamic Scoping is. I read through the page for a few minutes and actually still hadn't much of a clue. Then I went to this page: http://c2.com/cgi/wiki?DynamicScoping 
It's very easy to understand from these two paragraphs:
"In lexical scoping (and if you're the interpreter), you search in the local function (the function which is running now), then you search in the function (or scope) in which that function was defined, then you search in the function (scope) in which that function was defined, and so forth. "Lexical" here refers to text, in that you can find out what variable is being referred to by looking at the nesting of scopes in the program text.
In dynamic scoping, by contrast, you search in the local function first, then you search in the function that called the local function, then you search in the function that called that function, and so on, up the call stack. "Dynamic" refers to change, in that the call stack can be different every time a given function is called, and so the function might hit different variables depending on where it is called from."
In contrast to this the text here goes:
"In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable name's scope is a certain function, then its scope is the program text of the function definition: within that text, the variable name exists, and is bound to its variable, but outside that text, the variable name does not exist. By contrast, in dynamic scoping (or dynamic scope), if a variable name's scope is a certain function, then its scope is the time-period during which the function is executing: while the function is running, the variable name exists, and is bound to its variable, but after the function returns, the variable name does not exist. "
I don't know, but this doesn't make much sense to me. I'm trying to understand what it tries to express but it isn't easy, even though I know from the above explanation what the whole thing tries to express.
--Birgitschrange (talk) 10:55, 5 January 2013 (UTC)
replies: text: Your information is very helpful to me. I've developed the habit, when consulting WP, of going right to the talk pages, due to the (in my amateur opinion) unclear expositions I often find in articles (I nevertheless have benefitted greatly from WP and am grateful to all those who have worked on it). Actually, I have the same problem on the internet in general - it's hard to find good explanations. The explanation you have here seems to draw a very clear distinction. ---lifeform (talk) 00:43, 6 December 2014 (UTC)
thread_title: Understanding Lexical/Dynamic Scoping

message: I was hoping to find references to the history of variable scoping in the Basic programming language. Was Microsoft Visual Basic the first to implement this feature/concept?
Linhartr22 (talk) 16:51, 21 July 2013 (UTC)
thread_title:  Omission of Basic programming language 

message: File scope ends with a reference to C code that does not exist in the text. However, perhaps the author was referring to the Python code above (because of the function name)?  — Preceding unsigned comment added by Polariseke (talk • contribs) 04:24, 1 December 2014 (UTC)
thread_title:  Wrong reference to code 

message: In this diff https://en.wikipedia.org/w/index.php?title=Scope_%28computer_science%29&type=revision&diff=762080509&oldid=753892005 I am only responsible for the change in the perl code example. The Visual Editor invented all the other changes. 93.232.43.102 (talk) 14:56, 26 January 2017 (UTC)
thread_title:  Visual Editor 'invented' additional changes 

message: Fortran has BLOCK which in addition to the usual scope nesting, allows variables to be allocated.  More specifically, arrays can be allocated with dimension based on values when entering the BLOCK.  PL/I BEGIN blocks also do this, I believe inherited from ALGOL's BEGIN.  There is no mention of Fortran, BLOCK, PL/I, and its BEGIN.  As well as I know it, the lexical scope in C doesn't do allocation such that variables are still allocated at function entry. Gah4 (talk) 17:41, 31 July 2019 (UTC)
thread_title:  BLOCK and BEGIN 

message: The text and the code sample for the last Perl example simply do not match.
The code is a closure factory, the text describes a single function closing over  one variable. IMHO, a simpler code sample would be a better match for this article.
The code behaves like this (Perl v5.28.2):
sub increment_counter {
    my $counter = 0;
    return sub
    {
        return ++$counter;
    }
}
$c1 = increment_counter();
$c2 = increment_counter();
print &$c1(), "\n"; # -> 1
print &$c1(), "\n"; # -> 2
print &$c1(), "\n"; # -> 3
print &$c2(), "\n"; # -> 1
print &$c2(), "\n"; # -> 2
I changed (judging from browsing through the page history, it's probably a simple revert to some previous state) the code example to match the textual explanation:
{
  my $counter = 0;
  sub increment_counter {
      return  ++$counter;
  }
}
This does what's described. 
2A02:AB88:1541:8C00:5810:A015:AC18:6016 (talk) 13:25, 17 March 2021 (UTC)
thread_title:  
Perl example at Block scope section is obscure
 

message: The page has two "Lexical scope vs. dynamic scope" sections.  Need to eliminate one of them!  — Preceding unsigned comment added by 131.119.15.14 (talk) 14:38, 9 June 2022 (UTC)
thread_title:  Duplicated Lexical vs. Dynamic sections