SlideShare a Scribd company logo
1 of 40
COMCS 51101
Paradigm of Programming
Language
Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Chapter 2
Names, Scopes, and Bindings
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
The Notion of Binding Time
A name is a mnemonic character string used to represent variables, constants, operations,
types, and so on .
Names in most languages are identifiers (alphanumeric tokens)
A binding is an association between two things:
1. a name and
2. the thing it names.
Binding time is
the time at which a binding is created
OR
the time at which any implementation decision is made.
There are many different times at which binding decisions are taken
1. Language design time:
• the control flow constructs
• the set of fundamental (primitive) types
• the available constructors for creating complex types etc
2. Language implementation time: Most language manuals leave a variety of issues to the discretion of the
language implementer.
• the precision (number of bits) of the fundamental types
• the coupling of I/O to the operating system’s notion of files
• the organization and maximum sizes of stack and heap
• and the handling of run-time exceptions such as arithmetic overflow.
3. Program writing time:
• choose algorithms
• data structures
• and names.
4. Compile time:
• the mapping of high-level constructs to machine code
• including the layout of statically defined data in memory.
5. Link time: most compilers support separate compilation—compiling different modules of a program at different
times—and depend on the availability of a library of standard subroutines, a program is usually not complete
until the various modules are joined together by a linker.
• The linker chooses the overall layout of the modules with respect to one another, and resolves inter-module
references.
• When a name in one module refers to an object in another module, the binding between the two is not finalized
until link time.
6. Load time: Load time refers to the point at which the operating system loads the program into memory so that
it can run.
• In primitive operating systems, the choice of machine addresses for objects within the program was not
finalized until load time.
• Modern operating systems distinguish between virtual and physical addresses. Virtual addresses are chosen at
link time; physical addresses can actually change at run time.
• The processor’s memory management hardware translates virtual addresses into physical addresses during each
individual instruction at run time.
7. Run time: Run time is actually a very broad term that covers the entire span from the beginning to the end of
execution.
• Bindings of values to variables occur at run time, as do a host of other decisions that vary from language to
language
• Run time includes program start-up time, module entry time, elaboration time (the point at which a
declaration is first “seen”), subroutine call time, block entry time, and statement execution time.
The terms static and dynamic are generally used to refer to things bound before run time and at run time, respectively.
Static Binding Dynamic Binding
It refer to things bound before run time It refer to things bound at run time
Compiler-based language
implementation is more efficient as they
make earlier decisions
interpreter-based language
implementation is less efficient as they
make late decisions
Once compiled takes less time for
execution
Execution time is more
Some languages are difficult to compile
because their definitions require
fundamental decisions to be postponed
until run time, generally in order to
increase the flexibility or expressiveness
of the language eg. Smalltalk
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Storage Management
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Object Lifetime and Storage Management
Key events
1. Creation of objects
2. Creation of bindings
3. References to variables, subroutines, types, and so on, all of which use bindings
4. Deactivation and reactivation of bindings that may be temporarily unusable
5. Destruction of bindings
6. Destruction of objects
Important task is to distinguish between names and the objects to which they refer
Binding’s lifetime
The period of time between the creation and the destruction of a name-to-object binding
Object’s lifetime the time between the creation and destruction of an object
Object lifetimes generally correspond to one of three principal storage allocation mechanisms
1. Static objects.
2. Stack objects
3. Heap objects
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Static Allocation
Global variables are the obvious example of static objects
Static objects are given an absolute address that is retained throughout the program’s execution.
variables that are local to a single subroutine, but retain their values from one invocation to the next;
their space is statically allocated
Numeric and string-valued constant literals are also statically allocated
Eg. Numeric Constant A = B/14.7
String Constant printf(“hello, world !”)
Compilers produce a variety of tables that are used by runtime support routines for debugging, dynamic-type
checking, garbage collection, exception handling, and other purposes
Statically allocated objects whose value should not change during program execution (e.g., instructions,
constants, and certain run-time tables) are often allocated in protected, read-only memory, so that any
inadvertent attempt to write to them will cause a processor interrupt, allowing the operating system to
announce a run-time error.
Local variables are created when their subroutine is called and destroyed when it returns.
If the subroutine is called repeatedly, each invocation is said to create and destroy a separate instance of each local
variable
In C and Ada, constants are simply variables that can not be changed after elaboration time.
Their values, sometimes depend on other values that are not known until run time.
Such elaboration-time constants, when local to a recursive subroutine, must be allocated on the stack
Apart from local variables and elaboration-time constants, the compiler stores other information associated with the
subroutine:
Arguments and return values: Modern compilers keep these in registers whenever possible, but sometimes space in
memory is needed.
Temporaries: These are usually intermediate values produced in complex calculations. Again, a good compiler will keep
them in registers whenever possible
Bookkeeping information: includes the subroutine’s return address, a reference to the stack frame of the caller (also
called the dynamic link), additional saved registers, debugging information
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Stack-Based Allocation
• Language supports recursion, doesn’t support static allocation of local variables as the number of
instances of a variable that may need to exist at the same time.
• The natural nesting of subroutine calls makes it easy to allocate space for locals on a stack.
• Each instance of a subroutine at run time has its own frame (also called an activation record/AR) on the
stack
• Each frame contains arguments and return values, local variables, temporaries, and bookkeeping
information.
• Arguments to be passed to subsequent routines lie at the top of the frame, where the callee can easily
find them.
• The organization of the remaining information is implementation-dependent: it varies from one language,
machine, and compiler to another
• Maintenance of the stack is the responsibility of
1. subroutine calling sequence—the code executed by the caller immediately before and after the call
2. prologue (code executed at the beginning)
3. epilogue (code executed at the end) of the subroutine itself.
• The term “calling sequence” is used to refer to the combined operations of the caller, the prologue, and
the epilogue
Stack Based Allocation for Subroutine
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Heap-Based Allocation
• A heap is a region of storage in which sub-blocks can be allocated and deallocated at arbitrary times
• Heaps are used for
1. the dynamically allocated pieces of linked data structures,
2. and for objects like character strings, lists, and sets, whose size may change as a result of an
assignment statement or other update operation
Allocated Blocks Internal Fragmentation
External Fragmentation
Many storage-management algorithms maintain a single linked list—the free list—of heap blocks not
currently in use
Storage-management algorithms:
1. First Fit
2. Best Fit
3. Worst Fit
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Garbage Collection
Allocation of heap-based objects is done BY :
1. instantiating an object
2. appending to the end of a list
3. assigning a long value into a previously short string and so on.
Deallocation is explicit in C, C++, and Pascal.
In many languages objects are to be deallocated implicitly
The run-time library for such a language must then provide a garbage collection mechanism to identify
and reclaim unreachable objects.
Most functional and scripting languages require garbage collection, as imperative languages, including
Modula-3, Java, and C#.
Manual deallocation errors are the most common and costly bugs in real-world programs.
If an object is deallocated too soon, the program may get a dangling reference (accessing memory now
used by another object).
If an object is not deallocated at the end of its lifetime, then the program may “leak memory,” eventually
running out of heap space.
Deallocation errors are notoriously difficult to identify and fix.
Hence language designers and programmers consider automatic garbage collection an essential language
feature.
Garbage-collection algorithms have improved, reducing their run-time overhead;
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Scope Rules
The textual region of the program in which a binding is active is its scope
We can look at a C program and know which names refer to which objects at which points in the program based on purely
textual rules. For this reason, C is said to be statically scoped (some authors say lexically scoped 3).
Other languages, including APL, Snobol, and early dialects of Lisp, are dynamically scoped: their bindings depend on the flow
of execution at run time
A scope is the body of a module, class, subroutine, or structured control flow statement, also called a block.
Algol 68 and Ada use the term elaboration to refer to the process by which declarations become active when control first
enters a scope. Elaboration entails the creation of bindings.
At any given point in a program’s execution, the set of active bindings is called the current referencing environment. The set
is principally determined by static or dynamic scope rules. We shall see that a referencing environment generally corresponds
to a sequence of scopes that can be examined (in order) to find the current binding for a given name.
Referencing environments also depend on what are (in a confusing use of terminology) called binding rules
Deep binding, in which the choice is made when the reference is first created.
Shallow binding, in which the choice is made when the reference is finally used.
Static Scoping
Static (lexical) scoping, the bindings between names and objects can be determined at compile time by examining the text
of the program, without consideration of the flow of control at run time.
Nested Subroutines
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Modules
A major challenge in software development is distribution of work such that project can proceed on multiple fronts
simultaneously.
Modularization is a concept of information hiding, which makes objects and algorithms invisible, whenever possible,
to portions of the system that do not need them.
Modularized code reduces the “cognitive load” on the programmer by minimizing the amount of information required
to understand any given portion of the system.
In a well-designed program the interfaces between modules are as “narrow” (i.e., simple) as possible, and any design
decision that is likely to change is hidden inside a single module
Encapsulating Data and Subroutines
The information hiding provided by nested subroutines is limited to objects whose lifetime is the same as that of the
subroutine
When control returns from a subroutine
• its local variables will no longer be live
• & their values will be discarded.
Solution to this problem in the form
save statement in Fortran
static in C
own in Algol.
Modules as Abstractions
A module allows a collection of objects (subroutines, variables, types) to be encapsulated in such a way that
(1) objects inside are visible to each other, but
(2) objects on the inside are not visible on the outside unless explicitly exported, and
(3) objects outside are not visible on the inside unless explicitly imported.
Note that these rules affect only the visibility of objects; they do not affect their lifetime.
Ada, Java, and Perl, use the term package instead of module.
C++, C#, and PHP, use namespace
Module Types and Classes
Inheritance allows new classes to be defined as extensions or refinements of existing
classes.
Inheritance facilitates a programming style in which all or most operations are thought of as
belonging to objects, and in which new objects can inherit most of their operations from
existing objects, without the need to rewrite code.
Example
Simula-67, Smalltalk, Eiffel, C++, Java, and C#.
scripting languages : Python and Ruby
languages that are not usually considered object-oriented, including Modula-3, Ada 95, and
Oberon.
Object Orientation
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Dynamic Scoping
Languages with dynamic scoping : APL, Snobol, TEX early dialects of Lisp
In static scoping this program prints a 1.
If dynamic scoping is in effect, the output depends on the value read at line 8 at run time
• if the input is positive, the program prints a 2
• otherwise it prints a 1.
Why the difference?
Static scope rules require that the reference resolve to the closest lexically enclosing declaration, namely the global
n. Procedure first changes n to 1, and line 12 prints this value.
Dynamic scope rules, on the other hand, require that we choose the most recent, active binding for n at run time
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Dynamic Scoping The meaning of Names in a Scope
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Aliases
Two or more names that refer to the same object at the same point in the program are said to be aliases.
A name that can refer to more than one object at a given point in the program is said to be overloaded.
Consider the following code in C++
sum and x will be aliases
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Overloading
Operator Overloading in C++
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Polymorphism and Related Concepts
Overloading vs Coercion
Coercion is the process by which a compiler automatically converts a value of one type into a value of another type when
that second type is required by the surrounding context
“polymorphic” means “having multiple forms.”
It is applied to code—both data structures and subroutines—that can work with values of multiple types
1. Parametric polymorphism the code takes a type (or set of types) as a parameter, either explicitly or
implicitly.
• Also known and genericity.
• Ada, C++, Clu, Eiffel, Modula-3, Java, and C#
2. Subtype polymorphism the code is designed to work with values of some specific type T, but the
programmer can define additional types to be extensions or refinements of T
• Subtype polymorphism is fundamental to object-oriented languages, in which subtypes (classes) are
said to inherit the methods of their parent types.
• Inheritance
C++, Eiffel, Java, and C#, generally provide both generics and inheritance
Polymorphism types
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Binding of Referencing Environments
Static scope rules specify that the referencing environment depends on the lexical nesting of program blocks
in which names are declared.
Dynamic scope rules specify that the referencing environment depends on the order in which declarations
are encountered
• The referencing environment of print_routine must not be created until the routine is actually called by
print_selected_records.
• This late binding of the referencing environment of a subroutine that has been passed as a parameter is
known as shallow binding
• It is usually the default in languages with dynamic scoping.
For function older_than_threshold, by contrast, shallow binding may not work well.
Example, procedure print_selected_records happens to have a local variable named threshold, then the variable set
by the main program will not be visible when the function is finally called, and the predicate will be unlikely to work
correctly.
In such a situation, the code that originally passes the function as a parameter has a particular referencing
environment in mind; it does not want the routine to be called in any other environment.
Therefore makes sense to bind the environment at the time the routine is first passed as a parameter, and then
restore that environment when the routine is finally called.
This early binding of the referencing environment is known as deep binding.
It is also referred to as the funarg (function argument) problem in Lisp
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Subroutine Closures
Deep binding is implemented by creating an explicit representation of a referencing environment and bundling
it together with a reference to the subroutine.
The bundle as a whole is referred to as a closure
Deep binding is generally the default in languages with static (lexical) scoping
Shallow binding is usually the default in languages with dynamic scoping
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
First-Class Values
a value in a programming language is said to have first-class status if it can be passed as a parameter, returned from a
subroutine, or assigned to a variable
Simple types such as integers and characters are first-class values in most programming languages.
A “second-class” value can be passed as a parameter, but not returned from a subroutine or assigned into a variable
A “third-class” value cannot even be passed as a parameter
Classes in Smalltalk
Labels in C and C++
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
most imperative languages have limited extent: they are destroyed at the end of their scope’s execution
Unlimited Extent
Most functional languages specify that local objects have unlimited extent: their lifetimes continue indefinitely.
Their space can be reclaimed only when the garbage collection system is able to prove that they will never be
used again
Code in Scheme
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
Macro Expansion
C macros suffer from several limitations
• fact that they are implemented by textual substitution
• and are not understood by the rest of the compiler.
• they provide a naming and binding mechanism that is separate from the rest of the programming
language
DIVIDES(y + z, x) would be replaced by (!(x % y + z))
Ranjana Shevkar, Assistant Professor, Modern College
Ganeshkhind
A named constant is like a variable except that
1.you are required to give an initial value for a named constant where you declare it, and
2.you cannot change its value.
To declare a named constant, write const in front of its declaration. For example,
const int height = 8;
Named constant

More Related Content

What's hot

Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Iffat Anjum
 
Lecture 2 more about parallel computing
Lecture 2   more about parallel computingLecture 2   more about parallel computing
Lecture 2 more about parallel computingVajira Thambawita
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.MOHIT DADU
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronizationShakshi Ranawat
 
Computer architecture page replacement algorithms
Computer architecture page replacement algorithmsComputer architecture page replacement algorithms
Computer architecture page replacement algorithmsMazin Alwaaly
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overridingJavaTportal
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javajunnubabu
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)Prakhar Maurya
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And MultithreadingShraddha
 
Synchronous vs Asynchronous Programming
Synchronous vs Asynchronous ProgrammingSynchronous vs Asynchronous Programming
Synchronous vs Asynchronous Programmingjeetendra mandal
 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
 
Android async task
Android async taskAndroid async task
Android async taskMadhu Venkat
 

What's hot (20)

Complete Operating System notes
Complete Operating System notesComplete Operating System notes
Complete Operating System notes
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Semaphore
SemaphoreSemaphore
Semaphore
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Lecture 2 more about parallel computing
Lecture 2   more about parallel computingLecture 2   more about parallel computing
Lecture 2 more about parallel computing
 
String matching, naive,
String matching, naive,String matching, naive,
String matching, naive,
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronization
 
Computer architecture page replacement algorithms
Computer architecture page replacement algorithmsComputer architecture page replacement algorithms
Computer architecture page replacement algorithms
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overriding
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Synchronous vs Asynchronous Programming
Synchronous vs Asynchronous ProgrammingSynchronous vs Asynchronous Programming
Synchronous vs Asynchronous Programming
 
Java threads
Java threadsJava threads
Java threads
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Android async task
Android async taskAndroid async task
Android async task
 

Similar to Ch 2 Names scopes and bindings.pptx

Desired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptxDesired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptx4132lenin6497ram
 
Variables: names, bindings, type, scope
Variables: names, bindings, type, scopeVariables: names, bindings, type, scope
Variables: names, bindings, type, scopesuthi
 
Language translators
Language translatorsLanguage translators
Language translatorsAditya Sharat
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxAliyahAli19
 
Unit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptxUnit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptxAsst.prof M.Gokilavani
 
An introduction to_programming_with_c__threads 2005
An introduction to_programming_with_c__threads 2005An introduction to_programming_with_c__threads 2005
An introduction to_programming_with_c__threads 2005mohammad shayestehfar
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processorsRebaz Najeeb
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation filejithujithin657
 
Hands on kubernetes_container_orchestration
Hands on kubernetes_container_orchestrationHands on kubernetes_container_orchestration
Hands on kubernetes_container_orchestrationAmir Hossein Sorouri
 
seminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdfseminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdfkarunyamittapally
 
Introduction to Computers, the Internet and the Web
Introduction to Computers, the Internet and the WebIntroduction to Computers, the Internet and the Web
Introduction to Computers, the Internet and the WebAndy Juan Sarango Veliz
 
Intermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdfIntermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdfHimanshu883663
 
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Iffat Anjum
 

Similar to Ch 2 Names scopes and bindings.pptx (20)

Desired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptxDesired language characteristics – Data typing .pptx
Desired language characteristics – Data typing .pptx
 
Memory models in c#
Memory models in c#Memory models in c#
Memory models in c#
 
Variables: names, bindings, type, scope
Variables: names, bindings, type, scopeVariables: names, bindings, type, scope
Variables: names, bindings, type, scope
 
Language translators
Language translatorsLanguage translators
Language translators
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
 
Unit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptxUnit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptx
 
Unit 1
Unit 1Unit 1
Unit 1
 
An introduction to_programming_with_c__threads 2005
An introduction to_programming_with_c__threads 2005An introduction to_programming_with_c__threads 2005
An introduction to_programming_with_c__threads 2005
 
Chapter no 1
Chapter no 1Chapter no 1
Chapter no 1
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation file
 
Stay fresh
Stay freshStay fresh
Stay fresh
 
Hands on kubernetes_container_orchestration
Hands on kubernetes_container_orchestrationHands on kubernetes_container_orchestration
Hands on kubernetes_container_orchestration
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
seminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdfseminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdf
 
Unit 1
Unit 1Unit 1
Unit 1
 
My Developments
My DevelopmentsMy Developments
My Developments
 
Introduction to Computers, the Internet and the Web
Introduction to Computers, the Internet and the WebIntroduction to Computers, the Internet and the Web
Introduction to Computers, the Internet and the Web
 
Intermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdfIntermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdf
 
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2
 

More from RanjanaShevkar

More from RanjanaShevkar (8)

Chapter 7.pptx
Chapter 7.pptxChapter 7.pptx
Chapter 7.pptx
 
Chapter 6.pptx
Chapter 6.pptxChapter 6.pptx
Chapter 6.pptx
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
 
Chapter 7.pptx
Chapter 7.pptxChapter 7.pptx
Chapter 7.pptx
 
Chapter 6.pptx
Chapter 6.pptxChapter 6.pptx
Chapter 6.pptx
 
Paradigms of Programming Languages CH1-Introduction.pptx
Paradigms of Programming Languages CH1-Introduction.pptxParadigms of Programming Languages CH1-Introduction.pptx
Paradigms of Programming Languages CH1-Introduction.pptx
 
Ch2 how blockchain works
Ch2 how blockchain worksCh2 how blockchain works
Ch2 how blockchain works
 

Recently uploaded

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
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
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
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
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
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
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
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
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

Ch 2 Names scopes and bindings.pptx

  • 1. COMCS 51101 Paradigm of Programming Language Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind
  • 2. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Chapter 2 Names, Scopes, and Bindings
  • 3. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind The Notion of Binding Time A name is a mnemonic character string used to represent variables, constants, operations, types, and so on . Names in most languages are identifiers (alphanumeric tokens) A binding is an association between two things: 1. a name and 2. the thing it names. Binding time is the time at which a binding is created OR the time at which any implementation decision is made.
  • 4. There are many different times at which binding decisions are taken 1. Language design time: • the control flow constructs • the set of fundamental (primitive) types • the available constructors for creating complex types etc 2. Language implementation time: Most language manuals leave a variety of issues to the discretion of the language implementer. • the precision (number of bits) of the fundamental types • the coupling of I/O to the operating system’s notion of files • the organization and maximum sizes of stack and heap • and the handling of run-time exceptions such as arithmetic overflow. 3. Program writing time: • choose algorithms • data structures • and names. 4. Compile time: • the mapping of high-level constructs to machine code • including the layout of statically defined data in memory.
  • 5. 5. Link time: most compilers support separate compilation—compiling different modules of a program at different times—and depend on the availability of a library of standard subroutines, a program is usually not complete until the various modules are joined together by a linker. • The linker chooses the overall layout of the modules with respect to one another, and resolves inter-module references. • When a name in one module refers to an object in another module, the binding between the two is not finalized until link time. 6. Load time: Load time refers to the point at which the operating system loads the program into memory so that it can run. • In primitive operating systems, the choice of machine addresses for objects within the program was not finalized until load time. • Modern operating systems distinguish between virtual and physical addresses. Virtual addresses are chosen at link time; physical addresses can actually change at run time. • The processor’s memory management hardware translates virtual addresses into physical addresses during each individual instruction at run time. 7. Run time: Run time is actually a very broad term that covers the entire span from the beginning to the end of execution. • Bindings of values to variables occur at run time, as do a host of other decisions that vary from language to language • Run time includes program start-up time, module entry time, elaboration time (the point at which a declaration is first “seen”), subroutine call time, block entry time, and statement execution time.
  • 6. The terms static and dynamic are generally used to refer to things bound before run time and at run time, respectively. Static Binding Dynamic Binding It refer to things bound before run time It refer to things bound at run time Compiler-based language implementation is more efficient as they make earlier decisions interpreter-based language implementation is less efficient as they make late decisions Once compiled takes less time for execution Execution time is more Some languages are difficult to compile because their definitions require fundamental decisions to be postponed until run time, generally in order to increase the flexibility or expressiveness of the language eg. Smalltalk
  • 7. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Storage Management
  • 8. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Object Lifetime and Storage Management Key events 1. Creation of objects 2. Creation of bindings 3. References to variables, subroutines, types, and so on, all of which use bindings 4. Deactivation and reactivation of bindings that may be temporarily unusable 5. Destruction of bindings 6. Destruction of objects Important task is to distinguish between names and the objects to which they refer Binding’s lifetime The period of time between the creation and the destruction of a name-to-object binding Object’s lifetime the time between the creation and destruction of an object Object lifetimes generally correspond to one of three principal storage allocation mechanisms 1. Static objects. 2. Stack objects 3. Heap objects
  • 9. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Static Allocation Global variables are the obvious example of static objects Static objects are given an absolute address that is retained throughout the program’s execution. variables that are local to a single subroutine, but retain their values from one invocation to the next; their space is statically allocated Numeric and string-valued constant literals are also statically allocated Eg. Numeric Constant A = B/14.7 String Constant printf(“hello, world !”) Compilers produce a variety of tables that are used by runtime support routines for debugging, dynamic-type checking, garbage collection, exception handling, and other purposes Statically allocated objects whose value should not change during program execution (e.g., instructions, constants, and certain run-time tables) are often allocated in protected, read-only memory, so that any inadvertent attempt to write to them will cause a processor interrupt, allowing the operating system to announce a run-time error.
  • 10. Local variables are created when their subroutine is called and destroyed when it returns. If the subroutine is called repeatedly, each invocation is said to create and destroy a separate instance of each local variable In C and Ada, constants are simply variables that can not be changed after elaboration time. Their values, sometimes depend on other values that are not known until run time. Such elaboration-time constants, when local to a recursive subroutine, must be allocated on the stack Apart from local variables and elaboration-time constants, the compiler stores other information associated with the subroutine: Arguments and return values: Modern compilers keep these in registers whenever possible, but sometimes space in memory is needed. Temporaries: These are usually intermediate values produced in complex calculations. Again, a good compiler will keep them in registers whenever possible Bookkeeping information: includes the subroutine’s return address, a reference to the stack frame of the caller (also called the dynamic link), additional saved registers, debugging information
  • 11. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Stack-Based Allocation • Language supports recursion, doesn’t support static allocation of local variables as the number of instances of a variable that may need to exist at the same time. • The natural nesting of subroutine calls makes it easy to allocate space for locals on a stack. • Each instance of a subroutine at run time has its own frame (also called an activation record/AR) on the stack • Each frame contains arguments and return values, local variables, temporaries, and bookkeeping information. • Arguments to be passed to subsequent routines lie at the top of the frame, where the callee can easily find them. • The organization of the remaining information is implementation-dependent: it varies from one language, machine, and compiler to another • Maintenance of the stack is the responsibility of 1. subroutine calling sequence—the code executed by the caller immediately before and after the call 2. prologue (code executed at the beginning) 3. epilogue (code executed at the end) of the subroutine itself. • The term “calling sequence” is used to refer to the combined operations of the caller, the prologue, and the epilogue
  • 12. Stack Based Allocation for Subroutine
  • 13. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Heap-Based Allocation • A heap is a region of storage in which sub-blocks can be allocated and deallocated at arbitrary times • Heaps are used for 1. the dynamically allocated pieces of linked data structures, 2. and for objects like character strings, lists, and sets, whose size may change as a result of an assignment statement or other update operation Allocated Blocks Internal Fragmentation External Fragmentation
  • 14. Many storage-management algorithms maintain a single linked list—the free list—of heap blocks not currently in use Storage-management algorithms: 1. First Fit 2. Best Fit 3. Worst Fit
  • 15. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Garbage Collection Allocation of heap-based objects is done BY : 1. instantiating an object 2. appending to the end of a list 3. assigning a long value into a previously short string and so on. Deallocation is explicit in C, C++, and Pascal. In many languages objects are to be deallocated implicitly The run-time library for such a language must then provide a garbage collection mechanism to identify and reclaim unreachable objects. Most functional and scripting languages require garbage collection, as imperative languages, including Modula-3, Java, and C#. Manual deallocation errors are the most common and costly bugs in real-world programs. If an object is deallocated too soon, the program may get a dangling reference (accessing memory now used by another object). If an object is not deallocated at the end of its lifetime, then the program may “leak memory,” eventually running out of heap space. Deallocation errors are notoriously difficult to identify and fix. Hence language designers and programmers consider automatic garbage collection an essential language feature. Garbage-collection algorithms have improved, reducing their run-time overhead;
  • 16. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Scope Rules The textual region of the program in which a binding is active is its scope We can look at a C program and know which names refer to which objects at which points in the program based on purely textual rules. For this reason, C is said to be statically scoped (some authors say lexically scoped 3). Other languages, including APL, Snobol, and early dialects of Lisp, are dynamically scoped: their bindings depend on the flow of execution at run time A scope is the body of a module, class, subroutine, or structured control flow statement, also called a block. Algol 68 and Ada use the term elaboration to refer to the process by which declarations become active when control first enters a scope. Elaboration entails the creation of bindings. At any given point in a program’s execution, the set of active bindings is called the current referencing environment. The set is principally determined by static or dynamic scope rules. We shall see that a referencing environment generally corresponds to a sequence of scopes that can be examined (in order) to find the current binding for a given name. Referencing environments also depend on what are (in a confusing use of terminology) called binding rules Deep binding, in which the choice is made when the reference is first created. Shallow binding, in which the choice is made when the reference is finally used.
  • 17. Static Scoping Static (lexical) scoping, the bindings between names and objects can be determined at compile time by examining the text of the program, without consideration of the flow of control at run time.
  • 19.
  • 20. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Modules A major challenge in software development is distribution of work such that project can proceed on multiple fronts simultaneously. Modularization is a concept of information hiding, which makes objects and algorithms invisible, whenever possible, to portions of the system that do not need them. Modularized code reduces the “cognitive load” on the programmer by minimizing the amount of information required to understand any given portion of the system. In a well-designed program the interfaces between modules are as “narrow” (i.e., simple) as possible, and any design decision that is likely to change is hidden inside a single module Encapsulating Data and Subroutines The information hiding provided by nested subroutines is limited to objects whose lifetime is the same as that of the subroutine When control returns from a subroutine • its local variables will no longer be live • & their values will be discarded. Solution to this problem in the form save statement in Fortran static in C own in Algol.
  • 21. Modules as Abstractions A module allows a collection of objects (subroutines, variables, types) to be encapsulated in such a way that (1) objects inside are visible to each other, but (2) objects on the inside are not visible on the outside unless explicitly exported, and (3) objects outside are not visible on the inside unless explicitly imported. Note that these rules affect only the visibility of objects; they do not affect their lifetime. Ada, Java, and Perl, use the term package instead of module. C++, C#, and PHP, use namespace
  • 22.
  • 23. Module Types and Classes
  • 24. Inheritance allows new classes to be defined as extensions or refinements of existing classes. Inheritance facilitates a programming style in which all or most operations are thought of as belonging to objects, and in which new objects can inherit most of their operations from existing objects, without the need to rewrite code. Example Simula-67, Smalltalk, Eiffel, C++, Java, and C#. scripting languages : Python and Ruby languages that are not usually considered object-oriented, including Modula-3, Ada 95, and Oberon. Object Orientation
  • 25. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Dynamic Scoping
  • 26. Languages with dynamic scoping : APL, Snobol, TEX early dialects of Lisp In static scoping this program prints a 1. If dynamic scoping is in effect, the output depends on the value read at line 8 at run time • if the input is positive, the program prints a 2 • otherwise it prints a 1. Why the difference? Static scope rules require that the reference resolve to the closest lexically enclosing declaration, namely the global n. Procedure first changes n to 1, and line 12 prints this value. Dynamic scope rules, on the other hand, require that we choose the most recent, active binding for n at run time
  • 27. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Dynamic Scoping The meaning of Names in a Scope
  • 28. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Aliases Two or more names that refer to the same object at the same point in the program are said to be aliases. A name that can refer to more than one object at a given point in the program is said to be overloaded. Consider the following code in C++ sum and x will be aliases
  • 29. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Overloading
  • 31. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Polymorphism and Related Concepts Overloading vs Coercion Coercion is the process by which a compiler automatically converts a value of one type into a value of another type when that second type is required by the surrounding context “polymorphic” means “having multiple forms.” It is applied to code—both data structures and subroutines—that can work with values of multiple types
  • 32. 1. Parametric polymorphism the code takes a type (or set of types) as a parameter, either explicitly or implicitly. • Also known and genericity. • Ada, C++, Clu, Eiffel, Modula-3, Java, and C# 2. Subtype polymorphism the code is designed to work with values of some specific type T, but the programmer can define additional types to be extensions or refinements of T • Subtype polymorphism is fundamental to object-oriented languages, in which subtypes (classes) are said to inherit the methods of their parent types. • Inheritance C++, Eiffel, Java, and C#, generally provide both generics and inheritance Polymorphism types
  • 33. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Binding of Referencing Environments Static scope rules specify that the referencing environment depends on the lexical nesting of program blocks in which names are declared. Dynamic scope rules specify that the referencing environment depends on the order in which declarations are encountered
  • 34.
  • 35. • The referencing environment of print_routine must not be created until the routine is actually called by print_selected_records. • This late binding of the referencing environment of a subroutine that has been passed as a parameter is known as shallow binding • It is usually the default in languages with dynamic scoping. For function older_than_threshold, by contrast, shallow binding may not work well. Example, procedure print_selected_records happens to have a local variable named threshold, then the variable set by the main program will not be visible when the function is finally called, and the predicate will be unlikely to work correctly. In such a situation, the code that originally passes the function as a parameter has a particular referencing environment in mind; it does not want the routine to be called in any other environment. Therefore makes sense to bind the environment at the time the routine is first passed as a parameter, and then restore that environment when the routine is finally called. This early binding of the referencing environment is known as deep binding. It is also referred to as the funarg (function argument) problem in Lisp
  • 36. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Subroutine Closures Deep binding is implemented by creating an explicit representation of a referencing environment and bundling it together with a reference to the subroutine. The bundle as a whole is referred to as a closure Deep binding is generally the default in languages with static (lexical) scoping Shallow binding is usually the default in languages with dynamic scoping
  • 37. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind First-Class Values a value in a programming language is said to have first-class status if it can be passed as a parameter, returned from a subroutine, or assigned to a variable Simple types such as integers and characters are first-class values in most programming languages. A “second-class” value can be passed as a parameter, but not returned from a subroutine or assigned into a variable A “third-class” value cannot even be passed as a parameter Classes in Smalltalk Labels in C and C++
  • 38. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind most imperative languages have limited extent: they are destroyed at the end of their scope’s execution Unlimited Extent Most functional languages specify that local objects have unlimited extent: their lifetimes continue indefinitely. Their space can be reclaimed only when the garbage collection system is able to prove that they will never be used again Code in Scheme
  • 39. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind Macro Expansion C macros suffer from several limitations • fact that they are implemented by textual substitution • and are not understood by the rest of the compiler. • they provide a naming and binding mechanism that is separate from the rest of the programming language DIVIDES(y + z, x) would be replaced by (!(x % y + z))
  • 40. Ranjana Shevkar, Assistant Professor, Modern College Ganeshkhind A named constant is like a variable except that 1.you are required to give an initial value for a named constant where you declare it, and 2.you cannot change its value. To declare a named constant, write const in front of its declaration. For example, const int height = 8; Named constant