Concepts of Programming Languages
220 Chapter 5 Names, Bindings, and Scopes Consider the following JavaScript function, big, in which the two func- tions sub1 and ...
5.5 Scope 221 if (list[i] < list[j]) { int temp; temp = list[i]; list[i] = list[j]; list[j] = temp; } The scopes created by b ...
222 Chapter 5 Names, Bindings, and Scopes rather than a statement. In Scheme, a let construct is a call to the function LET with ...
5.5 Scope 223 The general form of a let construct in F# is as follows: let left_side = expression The left_side of let can be a ...
224 Chapter 5 Names, Bindings, and Scopes The for statements of C++, Java, and C# allow variable definitions in their initializa ...
5.5 Scope 225 In C++, a global variable that is hidden by a local with the same name can be accessed using the scope operator (: ...
226 Chapter 5 Names, Bindings, and Scopes if it has been declared to be global in the function. Consider the following examples: ...
5.5 Scope 227 Functions can be nested in Python. Variables defined in nesting functions are accessible in a nested function thro ...
228 Chapter 5 Names, Bindings, and Scopes Consider again the function big from Section 5.5.1, which is reproduced here, minus th ...
5.6 Scope and Lifetime 229 First, during the time span beginning when a subprogram begins its execu- tion and ending when that e ...
230 Chapter 5 Names, Bindings, and Scopes Scope and lifetime are also unrelated when subprogram calls are involved. Consider the ...
5.7 Referencing Environments 231 c = 9; # Creates a new local ... 2 def sub3(): nonlocal c: # Makes nonlocal c visible here g = ...
232 Chapter 5 Names, Bindings, and Scopes int c, d; ... 3 sub2(); } / end of main / The referencing environments of the indicate ...
5.8 Named Constants 233 program, this can be tedious and error prone. An easier and more reliable method is to use a named const ...
234 Chapter 5 Names, Bindings, and Scopes constructor.^12 So, if a program needs a constant-valued object whose value is the sam ...
Review Questions 235 Scalar variables can be separated into four categories by considering their lifetimes: static, stack dynami ...
236 Chapter 5 Names, Bindings, and Scopes Describe the encapsulation of an F# let inside a function and outside all functions. ...
Problem Set 237 a. Assuming static scoping, in the following, which dec- laration of x is the correct one for a reference to x? ...
238 Chapter 5 Names, Bindings, and Scopes List all the variables, along with the program units where they are declared, that are ...
Problem Set 239 int c, d, e; /* definition 3 */ ... 2 } ... 3 } ... 4 } For each of the four marked points in this function, lis ...
«
8
9
10
11
12
13
14
15
16
17
»
Free download pdf