SlideShare a Scribd company logo
1 of 8
Download to read offline
1
Chapter Ten Modern Programming Languages 1
Scope
Chapter Ten Modern Programming Languages 2
Reusing Names
īŽ Scope is trivial if you have a unique name
for everything:
īŽ But in modern languages, we often use the
same name over and over:
īŽ How can this work?
fun square n = n * n;
fun double n = n + n;
fun square a = a * a;
fun double b = b + b;
Chapter Ten Modern Programming Languages 3
Outline
īŽ Definitions and scope
īŽ Scoping with blocks
īŽ Scoping with labeled namespaces
īŽ Scoping with primitive namespaces
īŽ Dynamic scoping
īŽ Separate compilation
Chapter Ten Modern Programming Languages 4
Definitions
īŽ When there are different variables with the
same name, there are different possible
bindings for that name
īŽ Not just variables: type names, constant
names, function names, etc.
īŽ A definition is anything that establishes a
possible binding for a name
Chapter Ten Modern Programming Languages 5
Examples
fun square n = n * n;
fun square square = square * square;
const
Low = 1;
High = 10;
type
Ints = array [Low..High] of Integer;
var
X: Ints;
Chapter Ten Modern Programming Languages 6
Scope
īŽ There may be more than one definition for a
given name
īŽ Each occurrence of the name (other than a
definition) has to be bound according to one
of its definitions
īŽ An occurrence of a name is in the scope of a
given definition of that name whenever that
definition governs the binding for that
occurrence
2
Chapter Ten Modern Programming Languages 7
Examples
īŽ Each occurrence must be bound using one
of the definitions
īŽ Which one?
īŽ There are many different ways to solve this
scoping problem
- fun square square = square * square;
val square = fn : int -> int
- square 3;
val it = 9 : int
Chapter Ten Modern Programming Languages 8
Outline
īŽ Definitions and scope
īŽ Scoping with blocks
īŽ Scoping with labeled namespaces
īŽ Scoping with primitive namespaces
īŽ Dynamic scoping
īŽ Separate compilation
Chapter Ten Modern Programming Languages 9
Blocks
īŽ A block is any language construct that
contains definitions, and also contains the
region of the program where those
definitions apply
let
val x = 1;
val y = 2;
in
x+y
end
Chapter Ten Modern Programming Languages 10
Different ML Blocks
īŽ The let is just a block: no other purpose
īŽ A fun definition includes a block:
īŽ Multiple alternatives have multiple blocks:
īŽ Each rule in a match is a block:
fun cube x = x*x*x;
fun f (a::b::_) = a+b
| f [a] = a
| f [] = 0;
case x of (a,0) => a | (_,b) => b
Chapter Ten Modern Programming Languages 11
Java Blocks
īŽ In Java and other C-like languages, you can
combine statements into one compound
statement using { and }
īŽ A compound statement also serves as a
block:
while (i < 0) {
int c = i*i*i;
p += c;
q += c;
i -= step;
}
Chapter Ten Modern Programming Languages 12
Nesting
īŽ What happens if a block
contains another block,
and both have definitions
of the same name?
īŽ ML example: what is the
value of this expression:
let
val n = 1
in
let
val n = 2
in
n
end
end
3
Chapter Ten Modern Programming Languages 13
Classic Block Scope Rule
īŽ The scope of a definition is the block
containing that definition, from the point of
definition to the end of the block, minus the
scopes of any redefinitions of the same
name in interior blocks
īŽ That is ML’s rule; most statically scoped,
block-structured languages use this or some
minor variation
Chapter Ten Modern Programming Languages 14
Example
let
val n = 1
in
let
val n = 2
in
n
end
end
Scope of this definition is A-B
Scope of this definition is B
A
B
Chapter Ten Modern Programming Languages 15
Outline
īŽ Definitions and scope
īŽ Scoping with blocks
īŽ Scoping with labeled namespaces
īŽ Scoping with primitive namespaces
īŽ Dynamic scoping
īŽ Separate compilation
Chapter Ten Modern Programming Languages 16
Labeled Namespaces
īŽ A labeled namespace is any language
construct that contains definitions and a
region of the program where those
definitions apply, and also has a name that
can be used to access those definitions from
outside the construct
īŽ ML has one called a structureâ€Ļ
Chapter Ten Modern Programming Languages 17
ML Structures
īŽ A little like a block: a can be used
anywhere from definition to the end
īŽ But the definitions are also available
outside, using the structure name: Fred.a
and Fred.f
structure Fred = struct
val a = 1;
fun f x = x + a;
end;
Chapter Ten Modern Programming Languages 18
Other Labeled Namespaces
īŽ Namespaces that are just namespaces:
– C++ namespace
– Modula-3 module
– Ada package
– Java package
īŽ Namespaces that serve other purposes too:
– Class definitions in class-based object-oriented
languages
4
Chapter Ten Modern Programming Languages 19
Example
īŽ The variables min and max would be
visible within the rest of the class
īŽ Also accessible from outside, as
Month.min and Month.max
īŽ Classes serve a different purpose too
public class Month {
public static int min = 1;
public static int max = 12;
â€Ļ
}
Chapter Ten Modern Programming Languages 20
Namespace Advantages
īŽ Two conflicting goals:
– Use memorable, simple names like max
– For globally accessible things, use uncommon
names like maxSupplierBid, names that
will not conflict with other parts of the program
īŽ With namespaces, you can accomplish both:
– Within the namespace, you can use max
– From outside, SupplierBid.max
Chapter Ten Modern Programming Languages 21
Namespace Refinement
īŽ Most namespace constructs have some way
to allow part of the namespace to be kept
private
īŽ Often a good information hiding technique
īŽ Programs are more maintainable when
scopes are small
īŽ For example, abstract data types reveal a
strict interface while hiding implementation
detailsâ€Ļ
Chapter Ten Modern Programming Languages 22
Example: An Abstract Data Type
namespace dictionary contains
a constant definition for initialSize
a type definition for hashTable
a function definition for hash
a function definition for reallocate
a function definition for create
a function definition for insert
a function definition for search
a function definition for delete
end namespace
Interface definitions should be visible
Implementation
definitions
should be hidden
Chapter Ten Modern Programming Languages 23
Two Approaches
īŽ In some languages, like C++, the
namespace specifies the visibility of its
components
īŽ In other languages, like ML, a separate
construct defines the interface to a
namespace (a signature in ML)
īŽ And some languages, like Ada and Java,
combine the two approaches
Chapter Ten Modern Programming Languages 24
Namespace Specifies Visibility
namespace dictionary contains
private:
a constant definition for initialSize
a type definition for hashTable
a function definition for hash
a function definition for reallocate
public:
a function definition for create
a function definition for insert
a function definition for search
a function definition for delete
end namespace
5
Chapter Ten Modern Programming Languages 25
Separate Interface
interface dictionary contains
a function type definition for create
a function type definition for insert
a function type definition for search
a function type definition for delete
end interface
namespace myDictionary implements dictionary contains
a constantdefinition for initialSize
a type definition for hashTable
a function definition for hash
a function definition for reallocate
a function definition for create
a function definition for insert
a function definition for search
a function definition for delete
end namespace
Chapter Ten Modern Programming Languages 26
Outline
īŽ Definitions and scope
īŽ Scoping with blocks
īŽ Scoping with labeled namespaces
īŽ Scoping with primitive namespaces
īŽ Dynamic scoping
īŽ Separate compilation
Chapter Ten Modern Programming Languages 27
Do Not Try This At Home
īŽ It is legal to have a variable named int
īŽ ML is not confused
īŽ You can even do this (ML understands that
int*int is not a type here):
- val int = 3;
val int = 3 : int
- fun f int = int*int;
val f = fn : int -> int
- f 3;
val it = 9 : int
Chapter Ten Modern Programming Languages 28
Primitive Namespaces
īŽ ML’s syntax keeps types and expressions
separated
īŽ ML always knows whether it is looking for
a type or for something else
īŽ There is a separate namespace for types
fun f(int:int) = (int:int)*(int:int);
These are in the
namespace for types
These are in the
ordinary namespace
Chapter Ten Modern Programming Languages 29
Primitive Namespaces
īŽ Not explicitly created using the language
(like primitive types)
īŽ They are part of the language definition
īŽ Some languages have several separate
primitive namespaces
īŽ Java: packages, types, methods, fields, and
statement labels are in separate namespaces
Chapter Ten Modern Programming Languages 30
Outline
īŽ Definitions and scope
īŽ Scoping with blocks
īŽ Scoping with labeled namespaces
īŽ Scoping with primitive namespaces
īŽ Dynamic scoping
īŽ Separate compilation
6
Chapter Ten Modern Programming Languages 31
When Is Scoping Resolved?
īŽ All scoping tools we have seen so far are
static
īŽ They answer the question (whether a given
occurrence of a name is in the scope of a
given definition) at compile time
īŽ Some languages postpone the decision until
runtime: dynamic scoping
Chapter Ten Modern Programming Languages 32
Dynamic Scoping
īŽ Each function has an environment of
definitions
īŽ If a name that occurs in a function is not
found in its environment, its caller’s
environment is searched
īŽ And if not found there, the search continues
back through the chain of callers
īŽ This generates a rather odd scope ruleâ€Ļ
Chapter Ten Modern Programming Languages 33
Classic Dynamic Scope Rule
īŽ The scope of a definition is the function
containing that definition, from the point of
definition to the end of the function, along
with any functions when they are called
(even indirectly) from within that scope—
minus the scopes of any redefinitions of the
same name in those called functions
Chapter Ten Modern Programming Languages 34
Static Vs. Dynamic
īŽ The scope rules are similar
īŽ Both talk about scope holes—places where
a scope does not reach because of
redefinitions
īŽ But the static rule talks only about regions
of program text, so it can be applied at
compile time
īŽ The dynamic rule talks about runtime
events: “functions when they are calledâ€Ļ”
Chapter Ten Modern Programming Languages 35
Example
fun g x =
let
val inc = 1;
fun f y = y+inc;
fun h z =
let
val inc = 2;
in
f z
end;
in
h x
end;
What is the value of
g 5 using ML’s classic
block scope rule?
Chapter Ten Modern Programming Languages 36
Block Scope (Static)
fun g x =
let
val inc = 1;
fun f y = y+inc;
fun h z =
let
val inc = 2;
in
f z
end;
in
h x
end;
With block scope,
the reference to inc is
bound to the previous
definition in the same
block. The definition in
f’s caller’s environment
is inaccessible.
g 5 = 6 in ML
7
Chapter Ten Modern Programming Languages 37
Dynamic Scope
fun g x =
let
val inc = 1;
fun f y = y+inc;
fun h z =
let
val inc = 2;
in
f z
end;
in
h x
end;
With dynamic scope,
the reference to inc is
bound to the definition
in the caller’s
environment.
g 5 = 7 if ML used
dynamic scope
Chapter Ten Modern Programming Languages 38
Where It Arises
īŽ Only in a few languages: some dialects of
Lisp and APL
īŽ Available as an option in Common Lisp
īŽ Drawbacks:
– Difficult to implement efficiently
– Creates large and complicated scopes, since
scopes extend into called functions
– Choice of variable name in caller can affect
behavior of called function
Chapter Ten Modern Programming Languages 39
Outline
īŽ Definitions and scope
īŽ Scoping with blocks
īŽ Scoping with labeled namespaces
īŽ Scoping with primitive namespaces
īŽ Dynamic scoping
īŽ Separate compilation
Chapter Ten Modern Programming Languages 40
Separate Compilation
īŽ We saw this in the classical sequence of
language system steps
īŽ Parts are compiled separately, then linked
together
īŽ Scope issues extend to the linker: it needs to
connect references to definitions across
separate compilations
īŽ Many languages have special support for
this
Chapter Ten Modern Programming Languages 41
C Approach, Compiler Side
īŽ Two different kinds of definitions:
– Full definition
– Name and type only: a declaration in C-talk
īŽ If several separate compilations want to use
the same integer variable x:
– Only one will have the full definition,
int x = 3;
– All others have the declaration
extern int x;
Chapter Ten Modern Programming Languages 42
C Approach, Linker Side
īŽ When the linker runs, it treats a declaration
as a reference to a name defined in some
other file
īŽ It expects to see exactly one full definition
of that name
īŽ Note that the declaration does not say where
to find the definition—it just requires the
linker to find it somewhere
8
Chapter Ten Modern Programming Languages 43
Modern Fortran Approach
īŽ A MODULE can define data in one separate
compilation
īŽ A USE statement can import those
definitions into another compilation
īŽ USE says what module to use, but does not
say what the definitions are
īŽ So unlike the C approach, the Fortran
compiler must at least look at the result of
that separate compilation
Chapter Ten Modern Programming Languages 44
Trends in Separate Compilation
īŽ In recent languages, separate compilation is
less separate than it used to be
– Java classes can depend on each other
circularly, so the Java compiler must be able to
compile separate classes simultaneously
– ML is not really suitable for separate
compilation at all, though CM (a separate tool
in the SML system, the Compilation Manager)
can do it for most ML programs
Chapter Ten Modern Programming Languages 45
Conclusion
īŽ Today: four approaches for scoping
īŽ There are many variations, and most
languages employ several at once
īŽ Remember: names do not have scopes,
definitions do!

More Related Content

What's hot

Difference between java and c#
Difference between java and c#Difference between java and c#
Difference between java and c#TECOS
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP ImplementationFridz Felisco
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
Babar: Knowledge Recognition, Extraction and Representation
Babar: Knowledge Recognition, Extraction and RepresentationBabar: Knowledge Recognition, Extraction and Representation
Babar: Knowledge Recognition, Extraction and RepresentationPierre de Lacaze
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammarmeresie tesfay
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Automatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSELAutomatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSELJoel Falcou
 
C++ programing lanuage
C++ programing lanuageC++ programing lanuage
C++ programing lanuageNimai Chand Das
 
Theory of Computation Lecture Notes
Theory of Computation Lecture NotesTheory of Computation Lecture Notes
Theory of Computation Lecture NotesFellowBuddy.com
 
Bc0052 theory of computer science
Bc0052   theory of computer scienceBc0052   theory of computer science
Bc0052 theory of computer sciencesmumbahelp
 
(Costless) Software Abstractions for Parallel Architectures
(Costless) Software Abstractions for Parallel Architectures(Costless) Software Abstractions for Parallel Architectures
(Costless) Software Abstractions for Parallel ArchitecturesJoel Falcou
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Keyappasami
 
HDR Defence - Software Abstractions for Parallel Architectures
HDR Defence - Software Abstractions for Parallel ArchitecturesHDR Defence - Software Abstractions for Parallel Architectures
HDR Defence - Software Abstractions for Parallel ArchitecturesJoel Falcou
 
C programming Ms. Pranoti Doke
C programming Ms. Pranoti DokeC programming Ms. Pranoti Doke
C programming Ms. Pranoti DokePranoti Doke
 
Deterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministicDeterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministicLeyo Stephen
 
Implementation
ImplementationImplementation
Implementationadil raja
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computationBipul Roy Bpl
 

What's hot (20)

Difference between java and c#
Difference between java and c#Difference between java and c#
Difference between java and c#
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
 
Intro Oop
Intro OopIntro Oop
Intro Oop
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Babar: Knowledge Recognition, Extraction and Representation
Babar: Knowledge Recognition, Extraction and RepresentationBabar: Knowledge Recognition, Extraction and Representation
Babar: Knowledge Recognition, Extraction and Representation
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammar
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Automatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSELAutomatic Task-based Code Generation for High Performance DSEL
Automatic Task-based Code Generation for High Performance DSEL
 
C++ programing lanuage
C++ programing lanuageC++ programing lanuage
C++ programing lanuage
 
Theory of Computation Lecture Notes
Theory of Computation Lecture NotesTheory of Computation Lecture Notes
Theory of Computation Lecture Notes
 
Bc0052 theory of computer science
Bc0052   theory of computer scienceBc0052   theory of computer science
Bc0052 theory of computer science
 
(Costless) Software Abstractions for Parallel Architectures
(Costless) Software Abstractions for Parallel Architectures(Costless) Software Abstractions for Parallel Architectures
(Costless) Software Abstractions for Parallel Architectures
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Key
 
HDR Defence - Software Abstractions for Parallel Architectures
HDR Defence - Software Abstractions for Parallel ArchitecturesHDR Defence - Software Abstractions for Parallel Architectures
HDR Defence - Software Abstractions for Parallel Architectures
 
C programming Ms. Pranoti Doke
C programming Ms. Pranoti DokeC programming Ms. Pranoti Doke
C programming Ms. Pranoti Doke
 
Deterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministicDeterministic context free grammars &non-deterministic
Deterministic context free grammars &non-deterministic
 
C++
C++C++
C++
 
1 puc programming using c++
1 puc programming using c++1 puc programming using c++
1 puc programming using c++
 
Implementation
ImplementationImplementation
Implementation
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 

Viewers also liked

Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715HelpWithAssignment.com
 
System Programming - Interprocess communication
System Programming - Interprocess communicationSystem Programming - Interprocess communication
System Programming - Interprocess communicationHelpWithAssignment.com
 
Get 24/7 Reliable Engineering Assignment Help, 100% error free, money back g...
Get 24/7 Reliable Engineering  Assignment Help, 100% error free, money back g...Get 24/7 Reliable Engineering  Assignment Help, 100% error free, money back g...
Get 24/7 Reliable Engineering Assignment Help, 100% error free, money back g...HelpWithAssignment.com
 
System Programming Assignment Help- Signals
System Programming Assignment Help- SignalsSystem Programming Assignment Help- Signals
System Programming Assignment Help- SignalsHelpWithAssignment.com
 
Manufacturing Process Selection and Design
Manufacturing Process Selection and DesignManufacturing Process Selection and Design
Manufacturing Process Selection and DesignHelpWithAssignment.com
 
Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715HelpWithAssignment.com
 
Game theory Bayesian Games at HelpWithAssignment.com
Game theory Bayesian Games at HelpWithAssignment.comGame theory Bayesian Games at HelpWithAssignment.com
Game theory Bayesian Games at HelpWithAssignment.comHelpWithAssignment.com
 
Tips for writing a good biography
Tips for writing a good biographyTips for writing a good biography
Tips for writing a good biographyHelpWithAssignment.com
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment HelpHelpWithAssignment.com
 
Network Programming Assignment Help
Network Programming Assignment HelpNetwork Programming Assignment Help
Network Programming Assignment HelpHelpWithAssignment.com
 
Customer relationship management
Customer relationship managementCustomer relationship management
Customer relationship managementHelpWithAssignment.com
 

Viewers also liked (14)

Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715
 
Factorial Experiments
Factorial ExperimentsFactorial Experiments
Factorial Experiments
 
System Programming - Interprocess communication
System Programming - Interprocess communicationSystem Programming - Interprocess communication
System Programming - Interprocess communication
 
Get 24/7 Reliable Engineering Assignment Help, 100% error free, money back g...
Get 24/7 Reliable Engineering  Assignment Help, 100% error free, money back g...Get 24/7 Reliable Engineering  Assignment Help, 100% error free, money back g...
Get 24/7 Reliable Engineering Assignment Help, 100% error free, money back g...
 
Scoping
ScopingScoping
Scoping
 
Cash Dividend Assignment Help
Cash Dividend Assignment Help Cash Dividend Assignment Help
Cash Dividend Assignment Help
 
System Programming Assignment Help- Signals
System Programming Assignment Help- SignalsSystem Programming Assignment Help- Signals
System Programming Assignment Help- Signals
 
Manufacturing Process Selection and Design
Manufacturing Process Selection and DesignManufacturing Process Selection and Design
Manufacturing Process Selection and Design
 
Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715Fundamentals of Transport Phenomena ChE 715
Fundamentals of Transport Phenomena ChE 715
 
Game theory Bayesian Games at HelpWithAssignment.com
Game theory Bayesian Games at HelpWithAssignment.comGame theory Bayesian Games at HelpWithAssignment.com
Game theory Bayesian Games at HelpWithAssignment.com
 
Tips for writing a good biography
Tips for writing a good biographyTips for writing a good biography
Tips for writing a good biography
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
Network Programming Assignment Help
Network Programming Assignment HelpNetwork Programming Assignment Help
Network Programming Assignment Help
 
Customer relationship management
Customer relationship managementCustomer relationship management
Customer relationship management
 

Similar to Modern Programming Languages Chapter on Scope and Namespaces

Python Namespace.pdf
Python Namespace.pdfPython Namespace.pdf
Python Namespace.pdfSudhanshiBakre1
 
C++ interview question
C++ interview questionC++ interview question
C++ interview questionDurgesh Tripathi
 
Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?Gerald Villorente
 
Mit4021 c# and .net
Mit4021   c# and .netMit4021   c# and .net
Mit4021 c# and .netsmumbahelp
 
What's in a Name?
What's in a Name?What's in a Name?
What's in a Name?Kevlin Henney
 
Bca1020 programming in c
Bca1020  programming in cBca1020  programming in c
Bca1020 programming in csmumbahelp
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interviewprashant patel
 
Learn C# programming - Interfaces & Namespaces
Learn C# programming - Interfaces & NamespacesLearn C# programming - Interfaces & Namespaces
Learn C# programming - Interfaces & NamespacesEng Teong Cheah
 
Inheritance
InheritanceInheritance
InheritanceJaya Kumari
 
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScriptLotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScriptBill Buchan
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsShanmuganathan C
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersSanjaya Prakash Pradhan
 
C++ Langauage Training in Ambala ! BATRA COMPUTER CENTRE
C++  Langauage Training in Ambala ! BATRA COMPUTER CENTREC++  Langauage Training in Ambala ! BATRA COMPUTER CENTRE
C++ Langauage Training in Ambala ! BATRA COMPUTER CENTREjatin batra
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++Amresh Raj
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfHouseMusica
 

Similar to Modern Programming Languages Chapter on Scope and Namespaces (20)

Python Namespace.pdf
Python Namespace.pdfPython Namespace.pdf
Python Namespace.pdf
 
Bp301
Bp301Bp301
Bp301
 
C++ interview question
C++ interview questionC++ interview question
C++ interview question
 
Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
 
Mit4021 c# and .net
Mit4021   c# and .netMit4021   c# and .net
Mit4021 c# and .net
 
What's in a Name?
What's in a Name?What's in a Name?
What's in a Name?
 
Bca1020 programming in c
Bca1020  programming in cBca1020  programming in c
Bca1020 programming in c
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
Learn C# programming - Interfaces & Namespaces
Learn C# programming - Interfaces & NamespacesLearn C# programming - Interfaces & Namespaces
Learn C# programming - Interfaces & Namespaces
 
Namespace
NamespaceNamespace
Namespace
 
Inheritance
InheritanceInheritance
Inheritance
 
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScriptLotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objects
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developers
 
C++ Langauage Training in Ambala ! BATRA COMPUTER CENTRE
C++  Langauage Training in Ambala ! BATRA COMPUTER CENTREC++  Langauage Training in Ambala ! BATRA COMPUTER CENTRE
C++ Langauage Training in Ambala ! BATRA COMPUTER CENTRE
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdf
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Modern Programming Languages Chapter on Scope and Namespaces

  • 1. 1 Chapter Ten Modern Programming Languages 1 Scope Chapter Ten Modern Programming Languages 2 Reusing Names īŽ Scope is trivial if you have a unique name for everything: īŽ But in modern languages, we often use the same name over and over: īŽ How can this work? fun square n = n * n; fun double n = n + n; fun square a = a * a; fun double b = b + b; Chapter Ten Modern Programming Languages 3 Outline īŽ Definitions and scope īŽ Scoping with blocks īŽ Scoping with labeled namespaces īŽ Scoping with primitive namespaces īŽ Dynamic scoping īŽ Separate compilation Chapter Ten Modern Programming Languages 4 Definitions īŽ When there are different variables with the same name, there are different possible bindings for that name īŽ Not just variables: type names, constant names, function names, etc. īŽ A definition is anything that establishes a possible binding for a name Chapter Ten Modern Programming Languages 5 Examples fun square n = n * n; fun square square = square * square; const Low = 1; High = 10; type Ints = array [Low..High] of Integer; var X: Ints; Chapter Ten Modern Programming Languages 6 Scope īŽ There may be more than one definition for a given name īŽ Each occurrence of the name (other than a definition) has to be bound according to one of its definitions īŽ An occurrence of a name is in the scope of a given definition of that name whenever that definition governs the binding for that occurrence
  • 2. 2 Chapter Ten Modern Programming Languages 7 Examples īŽ Each occurrence must be bound using one of the definitions īŽ Which one? īŽ There are many different ways to solve this scoping problem - fun square square = square * square; val square = fn : int -> int - square 3; val it = 9 : int Chapter Ten Modern Programming Languages 8 Outline īŽ Definitions and scope īŽ Scoping with blocks īŽ Scoping with labeled namespaces īŽ Scoping with primitive namespaces īŽ Dynamic scoping īŽ Separate compilation Chapter Ten Modern Programming Languages 9 Blocks īŽ A block is any language construct that contains definitions, and also contains the region of the program where those definitions apply let val x = 1; val y = 2; in x+y end Chapter Ten Modern Programming Languages 10 Different ML Blocks īŽ The let is just a block: no other purpose īŽ A fun definition includes a block: īŽ Multiple alternatives have multiple blocks: īŽ Each rule in a match is a block: fun cube x = x*x*x; fun f (a::b::_) = a+b | f [a] = a | f [] = 0; case x of (a,0) => a | (_,b) => b Chapter Ten Modern Programming Languages 11 Java Blocks īŽ In Java and other C-like languages, you can combine statements into one compound statement using { and } īŽ A compound statement also serves as a block: while (i < 0) { int c = i*i*i; p += c; q += c; i -= step; } Chapter Ten Modern Programming Languages 12 Nesting īŽ What happens if a block contains another block, and both have definitions of the same name? īŽ ML example: what is the value of this expression: let val n = 1 in let val n = 2 in n end end
  • 3. 3 Chapter Ten Modern Programming Languages 13 Classic Block Scope Rule īŽ The scope of a definition is the block containing that definition, from the point of definition to the end of the block, minus the scopes of any redefinitions of the same name in interior blocks īŽ That is ML’s rule; most statically scoped, block-structured languages use this or some minor variation Chapter Ten Modern Programming Languages 14 Example let val n = 1 in let val n = 2 in n end end Scope of this definition is A-B Scope of this definition is B A B Chapter Ten Modern Programming Languages 15 Outline īŽ Definitions and scope īŽ Scoping with blocks īŽ Scoping with labeled namespaces īŽ Scoping with primitive namespaces īŽ Dynamic scoping īŽ Separate compilation Chapter Ten Modern Programming Languages 16 Labeled Namespaces īŽ A labeled namespace is any language construct that contains definitions and a region of the program where those definitions apply, and also has a name that can be used to access those definitions from outside the construct īŽ ML has one called a structureâ€Ļ Chapter Ten Modern Programming Languages 17 ML Structures īŽ A little like a block: a can be used anywhere from definition to the end īŽ But the definitions are also available outside, using the structure name: Fred.a and Fred.f structure Fred = struct val a = 1; fun f x = x + a; end; Chapter Ten Modern Programming Languages 18 Other Labeled Namespaces īŽ Namespaces that are just namespaces: – C++ namespace – Modula-3 module – Ada package – Java package īŽ Namespaces that serve other purposes too: – Class definitions in class-based object-oriented languages
  • 4. 4 Chapter Ten Modern Programming Languages 19 Example īŽ The variables min and max would be visible within the rest of the class īŽ Also accessible from outside, as Month.min and Month.max īŽ Classes serve a different purpose too public class Month { public static int min = 1; public static int max = 12; â€Ļ } Chapter Ten Modern Programming Languages 20 Namespace Advantages īŽ Two conflicting goals: – Use memorable, simple names like max – For globally accessible things, use uncommon names like maxSupplierBid, names that will not conflict with other parts of the program īŽ With namespaces, you can accomplish both: – Within the namespace, you can use max – From outside, SupplierBid.max Chapter Ten Modern Programming Languages 21 Namespace Refinement īŽ Most namespace constructs have some way to allow part of the namespace to be kept private īŽ Often a good information hiding technique īŽ Programs are more maintainable when scopes are small īŽ For example, abstract data types reveal a strict interface while hiding implementation detailsâ€Ļ Chapter Ten Modern Programming Languages 22 Example: An Abstract Data Type namespace dictionary contains a constant definition for initialSize a type definition for hashTable a function definition for hash a function definition for reallocate a function definition for create a function definition for insert a function definition for search a function definition for delete end namespace Interface definitions should be visible Implementation definitions should be hidden Chapter Ten Modern Programming Languages 23 Two Approaches īŽ In some languages, like C++, the namespace specifies the visibility of its components īŽ In other languages, like ML, a separate construct defines the interface to a namespace (a signature in ML) īŽ And some languages, like Ada and Java, combine the two approaches Chapter Ten Modern Programming Languages 24 Namespace Specifies Visibility namespace dictionary contains private: a constant definition for initialSize a type definition for hashTable a function definition for hash a function definition for reallocate public: a function definition for create a function definition for insert a function definition for search a function definition for delete end namespace
  • 5. 5 Chapter Ten Modern Programming Languages 25 Separate Interface interface dictionary contains a function type definition for create a function type definition for insert a function type definition for search a function type definition for delete end interface namespace myDictionary implements dictionary contains a constantdefinition for initialSize a type definition for hashTable a function definition for hash a function definition for reallocate a function definition for create a function definition for insert a function definition for search a function definition for delete end namespace Chapter Ten Modern Programming Languages 26 Outline īŽ Definitions and scope īŽ Scoping with blocks īŽ Scoping with labeled namespaces īŽ Scoping with primitive namespaces īŽ Dynamic scoping īŽ Separate compilation Chapter Ten Modern Programming Languages 27 Do Not Try This At Home īŽ It is legal to have a variable named int īŽ ML is not confused īŽ You can even do this (ML understands that int*int is not a type here): - val int = 3; val int = 3 : int - fun f int = int*int; val f = fn : int -> int - f 3; val it = 9 : int Chapter Ten Modern Programming Languages 28 Primitive Namespaces īŽ ML’s syntax keeps types and expressions separated īŽ ML always knows whether it is looking for a type or for something else īŽ There is a separate namespace for types fun f(int:int) = (int:int)*(int:int); These are in the namespace for types These are in the ordinary namespace Chapter Ten Modern Programming Languages 29 Primitive Namespaces īŽ Not explicitly created using the language (like primitive types) īŽ They are part of the language definition īŽ Some languages have several separate primitive namespaces īŽ Java: packages, types, methods, fields, and statement labels are in separate namespaces Chapter Ten Modern Programming Languages 30 Outline īŽ Definitions and scope īŽ Scoping with blocks īŽ Scoping with labeled namespaces īŽ Scoping with primitive namespaces īŽ Dynamic scoping īŽ Separate compilation
  • 6. 6 Chapter Ten Modern Programming Languages 31 When Is Scoping Resolved? īŽ All scoping tools we have seen so far are static īŽ They answer the question (whether a given occurrence of a name is in the scope of a given definition) at compile time īŽ Some languages postpone the decision until runtime: dynamic scoping Chapter Ten Modern Programming Languages 32 Dynamic Scoping īŽ Each function has an environment of definitions īŽ If a name that occurs in a function is not found in its environment, its caller’s environment is searched īŽ And if not found there, the search continues back through the chain of callers īŽ This generates a rather odd scope ruleâ€Ļ Chapter Ten Modern Programming Languages 33 Classic Dynamic Scope Rule īŽ The scope of a definition is the function containing that definition, from the point of definition to the end of the function, along with any functions when they are called (even indirectly) from within that scope— minus the scopes of any redefinitions of the same name in those called functions Chapter Ten Modern Programming Languages 34 Static Vs. Dynamic īŽ The scope rules are similar īŽ Both talk about scope holes—places where a scope does not reach because of redefinitions īŽ But the static rule talks only about regions of program text, so it can be applied at compile time īŽ The dynamic rule talks about runtime events: “functions when they are calledâ€Ļ” Chapter Ten Modern Programming Languages 35 Example fun g x = let val inc = 1; fun f y = y+inc; fun h z = let val inc = 2; in f z end; in h x end; What is the value of g 5 using ML’s classic block scope rule? Chapter Ten Modern Programming Languages 36 Block Scope (Static) fun g x = let val inc = 1; fun f y = y+inc; fun h z = let val inc = 2; in f z end; in h x end; With block scope, the reference to inc is bound to the previous definition in the same block. The definition in f’s caller’s environment is inaccessible. g 5 = 6 in ML
  • 7. 7 Chapter Ten Modern Programming Languages 37 Dynamic Scope fun g x = let val inc = 1; fun f y = y+inc; fun h z = let val inc = 2; in f z end; in h x end; With dynamic scope, the reference to inc is bound to the definition in the caller’s environment. g 5 = 7 if ML used dynamic scope Chapter Ten Modern Programming Languages 38 Where It Arises īŽ Only in a few languages: some dialects of Lisp and APL īŽ Available as an option in Common Lisp īŽ Drawbacks: – Difficult to implement efficiently – Creates large and complicated scopes, since scopes extend into called functions – Choice of variable name in caller can affect behavior of called function Chapter Ten Modern Programming Languages 39 Outline īŽ Definitions and scope īŽ Scoping with blocks īŽ Scoping with labeled namespaces īŽ Scoping with primitive namespaces īŽ Dynamic scoping īŽ Separate compilation Chapter Ten Modern Programming Languages 40 Separate Compilation īŽ We saw this in the classical sequence of language system steps īŽ Parts are compiled separately, then linked together īŽ Scope issues extend to the linker: it needs to connect references to definitions across separate compilations īŽ Many languages have special support for this Chapter Ten Modern Programming Languages 41 C Approach, Compiler Side īŽ Two different kinds of definitions: – Full definition – Name and type only: a declaration in C-talk īŽ If several separate compilations want to use the same integer variable x: – Only one will have the full definition, int x = 3; – All others have the declaration extern int x; Chapter Ten Modern Programming Languages 42 C Approach, Linker Side īŽ When the linker runs, it treats a declaration as a reference to a name defined in some other file īŽ It expects to see exactly one full definition of that name īŽ Note that the declaration does not say where to find the definition—it just requires the linker to find it somewhere
  • 8. 8 Chapter Ten Modern Programming Languages 43 Modern Fortran Approach īŽ A MODULE can define data in one separate compilation īŽ A USE statement can import those definitions into another compilation īŽ USE says what module to use, but does not say what the definitions are īŽ So unlike the C approach, the Fortran compiler must at least look at the result of that separate compilation Chapter Ten Modern Programming Languages 44 Trends in Separate Compilation īŽ In recent languages, separate compilation is less separate than it used to be – Java classes can depend on each other circularly, so the Java compiler must be able to compile separate classes simultaneously – ML is not really suitable for separate compilation at all, though CM (a separate tool in the SML system, the Compilation Manager) can do it for most ML programs Chapter Ten Modern Programming Languages 45 Conclusion īŽ Today: four approaches for scoping īŽ There are many variations, and most languages employ several at once īŽ Remember: names do not have scopes, definitions do!