30 Pages

Lecture3

Course: G 22, Fall 2008
School: NYU
Rating:
 
 
 
 
 

Word Count: 1151

Document Preview

Scopes Names, and Bindings 1 Names Kinds of names Binding associates a names with an object A Name is an abstraction of an object Variables, functions, classes, types, labels, blocks, operators, tasks, etc. Name Spaces Classes are type abstractions Variables are data abstractions Subroutines are control abstractions separate lists of names, struct ids in C 2 Binding Binding Times...

Register Now

Unformatted Document Excerpt

Coursehero >> New York >> NYU >> G 22

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Scopes Names, and Bindings 1 Names Kinds of names Binding associates a names with an object A Name is an abstraction of an object Variables, functions, classes, types, labels, blocks, operators, tasks, etc. Name Spaces Classes are type abstractions Variables are data abstractions Subroutines are control abstractions separate lists of names, struct ids in C 2 Binding Binding Times Language Design time Compile Time Keywords Builtin Types Load Time Binding variables to locations in memory Static linking Interpreted Languages e.g., Smalltalk Dynamic linking Polymorphism Run Time Late binding => flexibility Early binding => safety 3 Object Lifetime A short biography of an Object Storage Allocation Mechanisms Creation of Object instantiation Creation of Names declaration Binding Name and Object Destruction of Bindings Destruction of Objects Static objects exist throughout execution of program Heap objects explicitly created Constants, global values, static members in C static keyword overloaded, multiple meanings Garbage collected or explicitly deleted Stack objects exist within a block 4 Function Calls Stack Allocation Compiler determines size of stack frame Stack allocation for declarations in block statements Advantages of Stack Allocation Stack frame pushed onto stack when function is called at run time Stack frame popped off stack when function returns Prologue and Epilog Parameters Local Variables Temporary (compiler generated) variables Bookkeeping information Allocation is automatic Reentrant allows for recursive calls Space & Time efficient Guarantees no side effects 5 Heap Allocation Heap is random access memory Allocation must be explicit Sequentially addressed memory Requires Memory Management System malloc() in C; new in C++ & Java Can be expensive Deallocation can be explicit or Garbage Collected Memory leaks Memory fragmentation Dangling references Susceptible to Problems 6 Scope Scope is the region over which a binding is active Examples: Static (Lexical) scope Binding at compile time Dynamic scope Binding at runtime 7 Function Scope labels Block (Local) Scope File Scope in C & C++ Package Scope in Java Class Scope Static Scope Most common: Binding determined by (lexical) structure of program C, C++, Java, etc. void Foo (char x) { char c = `a'; Fum (x); } void Fum(char y) { c = y; Error } 8 Nested Subroutines Supported in Pascal, Ada, ML Useful for "helper" functions function m return Integer is { x is Integer; function sub1 return Integer is { } Requires a static chain of pointers or a display to keep track of environments on the stack 9 } sub1(); return x; x := 1 Static Chains A() { B() { C() {} D() {} } E() {} } Nested Calls: C D B E A 10 A, E, B, D, C Dynamic Scope Scope determined at runtime A variable local to a calling function will be available in the called function. Requires dynamic chain of pointers to keep track of calling environments APL, Snobol, Perl 11 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. a : integer global declaration procedure first a := 1 procedure second a: integer first() a := 2 if read_integer() > 0 second() else first() write_integer(a) What is the result under Static Scope? What is the result under Dynamic Scope? Static vs Dynamic Scope 12 Visibility A Binding may be temporarily hidden by a more local binding. Linkage names must be exported to be visible Hidden declarations may be referenced using a qualified name int x = 0; int y = Super.x; 13 Name Overloading Same name used for more than one distinct function Builtin operators Function (or operator) names resolved using actual argument types Example: 1.0 + 2.0 and 1 + 2 Name Mangling in C++ 14 Access Control Declaration is in scope and not hidden, but access is controlled Applies to class members Private only accessible in this class Public available access throughout scope Protected accessible in this class and its subclasses Package accessible in all classes in package 15 Type Checking 16 What's in a Type A type is (possibly infinite) set of values and the set of valid operations on those values A Type System is a set of formal rules that defines a type, including rules for Integer infinite set of discrete values and operators, e.g., succ(), pred(), +, , *, /, etc. Constructing a new instance of the type Determining type equivalence between values Determining type compatibility between values Defining and applying operators 17 Type Declaration Not all languages require explicit type delcaration: Type implicit in name Type inferred from context Perl: $ => scalar, @ => array Basic: $ => string x + 1.0; Type associated with values, rather than names Explicit declaration may not be necessary, but: x := "abc"; x := 2.0; x + 1.0; Makes program easier to understand Avoids common errors such as misspelling an identifier 18 Type Declaration (2) What does a type declaration do? a is array (1..10) of Integer Defines set of valid operations on a Defines set of valid operations on elements of a Establishes size of a in memory Registers a in symbol table Determines scope of a May allocate storage and bind name to object 19 *1st, 2nd & 3rd Class values First class values Second class values Can be passed as parameters Can be stored in variables Cannot be passed as parameters Can be stored in variables Cannot be passed as parameters Cannot be stored in variables 20 Third class values Type Checking Use of incompatible types is called a "type clash" Statically typed: Example: a is Array (1..10) of Integer; a[20] := `a'; Dynamically typed Type errors detectable at compile time Most Algolstyle languages Type errors detected at runtime Scheme, Smalltalk Static typing is preferable but not always possible 21 Strong vs Weak Typing Strongly typed Languages Weakly typed languages Type rules strictly enforced at compile time Ada, Java Possibly unsafe type conversion permitted Assembly, C Structural vs. Name equivalence Coercion Promotion Polymorphism Type Equivalence of composite types Type Compatibility 22 *Type Semantics Denotational Semantics Constructive A type is a set of values Operations are values of type ...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

NYU - G - 22
Adding Pronoun Constraints to a Grammar:Verbs and Pronouns Present tense verbs occur in two forms: singular: eats plural: eat only exception is be, which has a third form, I am Pronouns differ in person, number, and case:1st person 2nd perso
NYU - V - 22
IntroductiontoComputersand Programming Lecture13:UserdefinedmethodsInstructor:EvanKorth NewYorkUniversityRoadMap Method abstraction Divide and conquer Examine parameters Examine return types Argument promotion Reading: 4.1-4.3, part 4.4, 4.
NYU - V - 22
Fundamentals of Computer Science Using CMidterm for V22.0380, section 1 Spring 1999 8:30 9:45 a.m. March 10, 1999 Instructor: Dilshad M. ShahidName: _ Student ID: _About the exam: Please read 1. This is a closed book exam. 2. You have the entir
NYU - DOCS - 6092
RANTS, RUMINATIONS, AND TRUE CONFESSIONS: THE ART OF THE POPULAR ESSAY Professor Mark Dery Forget everything you know about the essay, especially that academic straitjacket known as "the term paper." Forget, too, those brain-dead op-eds that appear i
NYU - FAS - 6092
RANTS, RUMINATIONS, AND TRUE CONFESSIONS: THE ART OF THE POPULAR ESSAY Professor Mark Dery Forget everything you know about the essay, especially that academic straitjacket known as "the term paper." Forget, too, those brain-dead op-eds that appear i
NYU - DOCS - 9258
ABOUT FACE NINA HIENSPRING 2009Walter Benjamin writes that the human countenance (and its accom p anying portraits) is the last holdout of aura and the ritual value of art. Reading the face has been
NYU - FAS - 9258
ABOUT FACE NINA HIENSPRING 2009Walter Benjamin writes that the human countenance (and its accom p anying portraits) is the last holdout of aura and the ritual value of art. Reading the face has been
NYU - PAB - 346
Building Concepts #1PremiseEscape from N.Y.C -Gimme Shelter -I'm Outta of HereInspiration MaterialsNew York Post, Friday, September 16,2005 The report cited from New York Post 75% of New Yorkers do not know where the nearest evacuation center
NYU - EJF - 251
DEFINE LCD_DREG PORTB 'LCD data port DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4 DEFINE LCD_RSREG PORTD 'LCD register select port DEFINE LCD_RSBIT 1 'LCD register select bit DEFINE LCD_EREG PORTD 'LCD enable port DEFINE LCD_EBIT 0 'LCD enabl
NYU - A - 273
ON THE ECONOMY:To bring our economy out of recession, we delivered the largest tax relief in ageneration.ON THE ECONOMY:Our first goal is clear: We must have an economy that grows fast enough toemploy every man and woman who seeks a job.ON
NYU - AP - 1607
*You've hiked through Snake Canyon once before while visiting your Uncle Howard at Red Creek Ranch, but you never noticed any cave entrance. It looks as though a recent rock slide has uncovered it.Though the late afternoon sun is striking the ope
NYU - AS - 7805
ffd8ffe000104a464 9460001020100c80 0c80000ffe20c58494 ffd8ffe000104a4649460001010100a600a40000ffe20 3435f50524f46494c c584943435f50524f46494c4500010100000c484c696 4500010100000c48 e6f021000006d6e74725247422058595a2007ce0002 4c696e6f021000006 00090006
NYU - POLITICS - 7805
ffd8ffe000104a464 9460001020100c80 0c80000ffe20c58494 ffd8ffe000104a4649460001010100a600a40000ffe20 3435f50524f46494c c584943435f50524f46494c4500010100000c484c696 4500010100000c48 e6f021000006d6e74725247422058595a2007ce0002 4c696e6f021000006 00090006
NYU - V - 22
/ welcome1/ Welcome to Java: Text-printing program.public class welcome1 { / main method begins execution of Java application public static void main( String args[] ) { System.out.println( "Welcome to Java!" ); } / end method m
NYU - V - 22
/ carpets_1import javax.swing.JOptionPane;public class carpets_1 { public static void main( String[] args ) {int length=0, width=0, total_area=0, number_of_rooms=0, count_rooms=1, carpet_int;double carpet_cost, total_cost; / Pro
NYU - V - 22
Computer ArchitectureV22.0436 Fall 2002Homework 2.Due Thursday, October 17 in class.Answer the following questions (using pen/pencil and paper)in Chapters 3 and 4 of Patterson & Hennessy:3.124.2, 4.4, 4.10, 4.43, 4.46
NYU - G - 89
G89.2229AdvancedRegression Spring2004 Exercise#6 DueMarch3,2004 ThisexercisemakesuseofaportionofthemiscarriageCESDdataset.Oftenresearchersare interestedinprocess,butuseacrosssectionalsurveydesigninsteadofalongitudinaldesignto describetheprocess.Fo
NYU - AMB - 576
Andrea BurghartDance & LiteracyMoving Forward. What is Dance Literacy?"Dance, drama, musical and the visual arts as different and distinct forms of representation or sign and symbols systems are vital to the development of the whole perso
NYU - UNIT - 1
CONTEMPORARY PRACTICE OF THE UNITED STATES RELATING TO INTERNATIONAL LAW Edited By Sean D. MurphySTATE REPRESENTATIONDepartment of State Letter to U.S. Court After LaGrand Decision On June 27, 2001, the International Court of Justice (ICJ) issued
NYU - V - 22
Computers Are Your Future 2005 Prentice-Hall, Inc.Computers Are Your Future Chapter 6Computers Are Your FutureChapter 6 Networks: Communicating and Sharing Resources 2005 Prentice-Hall, Inc Slide 2Computers Are Your Future Chapter 6What
NYU - G - 22
QuickLanguageTour ProgrammingLanguagesI Fall2003Languageswedidnotlookat Withaquicksurveyofwhatis interestingabouteachone FORTRAN Theearliestalgorithmiclanguage(50s) Inventedtheideaofa*b+c*d Multidimensionalarrays Subprograms(butnorecursion)
NYU - V - 22
Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value (key) of each object (smaller value higher priority, or higher value higher priority) Example Applications: printer ->
NYU - V - 22
Computer Science 2 Data Structures and Algorithms V22.0102 section 2 Introduction to TreesProfessor: Evan Korth New York UniversityRoad Map Introduction to trees Terminology Binary trees Tree traversal Reading: 4.1 4.2Tree Tree defined r
UT Arlington - CHAPTER - 14
Chapter 14 Our Galaxy14.1 The Milky Way Revealed Our Goals for Learning What does our galaxy look like? How do stars orbit in our galaxy?What does our galaxy look like?The Milky Way galaxy appears in our sky as a faint band of lightDusty g
UT Arlington - CHAPTER - 3304
Chapter 14 Our Galaxy14.1 The Milky Way Revealed Our Goals for Learning What does our galaxy look like? How do stars orbit in our galaxy?What does our galaxy look like?The Milky Way galaxy appears in our sky as a faint band of lightDusty g
NYU - G - 22
Homework on BAN logicAssigned by: Avi RubinDue: Tuesday, November 19BAN logic was used to show that the Needham and Schroeder protocolhas a design flaw.1. What is wrong with the protocol?2. Provide a modified Needham and Schroeder protocol
NYU - V - 22
import javax.swing.JOptionPane;public class july5ex4 { public static void main(String args[]) { int maxnum, kount; String inputString = JOptionPane.showInputDialog( null, "Type max number", "Max Number",
NYU - EDITION - 6
C Y672.1 751.6 696.8 779.2 737.1 810.3 767.9 864.7 762.8 857.5779.4 874.9 823.1 906.8 864.3 942.9 903.2 988.8 927.6 1015.7
NYU - VAGC - 0
OUTPUT_FILENAME lowz_dr4_9.txtOUTPUT_OPTION standardCOMPRESS_OPTION noneINPUT_COORDINATE_SYSTEM equatorialOUTPUT_COORDINATE_SYSTEM equatorialINPUT_EQUINOX J2000.0OUTPUT_EQUINOX J2000.0REDSHIFT
NYU - VAGC - 0
OUTPUT_FILENAME lowz_dr4_16.txtOUTPUT_OPTION standardCOMPRESS_OPTION noneINPUT_COORDINATE_SYSTEM equatorialOUTPUT_COORDINATE_SYSTEM equatorialINPUT_EQUINOX J2000.0OUTPUT_EQUINOX J2000.0REDSHIF
NYU - ATM - 262
Deriving the formula for the weights of an efficient portfolio with given Expected returnNotes - Aloke Mukherjee2 November 20051. What do we know?Portfolio has weights of each asset i: wi, each asset has expected return Mean(i), variance Cov(i,
NYU - V - 22
import javax.swing.JOptionPane;public class SumNTo2N{public static void main (String [] args){int n, low, high, total = 0;String nAsString = JOptionPane.showInputDialog ("Enter number:");n = Integer.parseInt (nAsString);if (n <
NYU - JSS - 344
Parshas Chukas1. Parsha Summary By: Rabbi Aron Tendler1st Aliya: The laws of the Parah Adumah- the Red Heifer, are detailed. 2nd Aliya: In Nissan of the 40th year, Miriam died. The well dried up and the nation gathered against Moshe and Aharon to
San Diego State - EDTEC - 590
Readings Packet for EDTEC 590 (Spring 08): Electronic Course Reserves Alden, J. (2007). Surveying attitudes: Questionnaires versus opinionnaires. Performance Improvement, 46(6), 4248. Andrade, H. (2007). Selfassessment through rubrics. Educational
San Diego State - BIO - 201
Reading: Chapter 33: 584585 Chapter 48: 853854 Chapter 49: 868869Lecture 4: FishesEarliest vertebrates jawless: lampreys Gnathostomes (Jawed Vertebrates) Evolution of Modern Fishes: 2 major groups Chondrichthyescartilage fish Osteichthyes
San Diego State - PSY - 760
Choline SupplementationCholine supplementation during pre and early postnatal development produces longlasting neuronal changes and cognitive enhancementCholine supplementation after prenatal alcohol mitigates learning deficitsCHOLINE SALINE N
San Diego State - GEO - 300
Cartography and GPSProjections A projection is a method of portraying the curved surface of the earth on a flay surface. Distortions of distance, direction, scale, and area always occur. Some projections preserve one property but distort the oth
San Diego State - GEO - 647
Cartography and GPSProjections A projection is a method of portraying the curved surface of the earth on a flay surface. Distortions of distance, direction, scale, and area always occur. Some projections preserve one property but distort the oth
San Diego State - CS - 596
3D Game Programming All in OneBy Kenneth C. FinneyChapter 4 Game ProgrammingGame ProgrammingTorque Script Strings Tagged and standard types Formatting codes Objects Methods and properties Namespaces Local, global, object, & arbitrary
San Diego State - GEOL - 552
EPA AND OTHER METHODS FOR HYDROCARBONS EPA Series 400 Methods Method # 413.2 418.2 Oil and Grease by infrared Petroleum by infraredEPA Series 500 Methods Analytical methods for the identification and measurement of volatile organic compounds (VOCs)
San Diego State - WORKSHOP - 29
Computational Chemistry Curriculum ToolsKim Baldridge San Diego Supercomputer Center University of California, San Diego http:www.sdsc.edu/~kimbJerry Greenberg San Diego Supercomputer Center http:www.sdsc.edu/~jpgJune 29, 1999NATIONAL PARTNERSH
San Diego State - WORKSHOP - 99
Computational Chemistry Curriculum ToolsKim Baldridge San Diego Supercomputer Center University of California, San Diego http:www.sdsc.edu/~kimbJerry Greenberg San Diego Supercomputer Center http:www.sdsc.edu/~jpgJune 29, 1999NATIONAL PARTNERSH
NYU - G - 89
G89.2228 Intermediate Statistics Fall 2001 Exercise #7: Power analysis Due October 31, 2001For all of these questions, write a sentence or describing the answer, and the method used to compute the result. If the method is an approximation, make tha
San Diego State - CS - 570
A sample data structure for N-level page tablesSample Data Structure2-level page table PageTable Contains information about the tree Level A structure describing a specific level of the page table. NextLevel Array of pointers to the next lev
NYU - V - 22
Artificial Intelligence Problem Set 1Assigned: Jan. 24 Due: Jan. 31Problem 1.A. Augment the family tree in the notes with the following facts about married couples: married(philip, elizabeth). married(elizabeth,
San Diego State - CONFERENCE - 07
Womens Experiences of NurseMidwifery Presence During ChildbirthPresenter: Lauren P. Hunter, PhD, CNM Ph: 858-454-9033 email: lhunter@mail.sdsu.edu Affiliation : San Diego State University School of Nursing STTI Chapters: Gamma Gamma, Zeta Mu Funding
NYU - EDITION - 6
Year C P Wp I K1 X Wg G T 1920 39.8 12.7 28.8 2.7 180.1 44.9 2.2 2.4 3.41921 41.9 12.4 25.5 -0.2 182.8 45.6 2.7 3.9 7.71922 45.0 16.9 29.3 1.9 182.6 50.1 2.9 3.2 3.91923 49.2 18.4 34.1 5.2 184.5 57.2 2.9 2.8 4.
NYU - G - 89
G89.2228 Intermediate Statistics Fall 2001 Exercise #2 1. Due September 26, 2001You have been assigned a random sample of 20 CESD scores on women who had experienced a miscarriage approximately two weeks earlier. Enter these data into a computer so
Central Mich. - BIO - 326
Announcements1. Survey results: 87% like powerpoint 85% print notes before class 93% thought exam 1 covered appropriate material 43% thought exam 1 was appropriate length Suggestions I will consider: posting lecture notes earlier, making exam 2 a bi
Central Mich. - FRANC - 1
Earth Facts Icebreaker QuestionsWhat is the largest lake in the world? By size and volume it is the Caspian Sea, located between southeast Europe and west Asia.Which of the following sources stores the greatest volume of fresh water worldwide: lak
Central Mich. - FRANC - 1
Study Guide for ClimateMelting permafrost and climate change questionDescribe the positive feedback loop impacting climate on up to 1/5 of the earth's surface.The Value Of An Education question There is no question for this podcast but reflect,
Central Mich. - FRANC - 1
A teachers frustration (actual posting on the ESPRIT earth science listserv) I'm enjoying reading the various approaches we teachers use for test/grade improvement. However, I'm still looking for something that might work for me and my students. Two
Central Mich. - BIS - 667
Chapter 5Business-to-Business Strategies: From Electronic Data Interchange to Electronic CommerceLearning ObjectivesIn this chapter, you will learn about: Strategies that businesses use to improve purchasing, logistics, and other support activ
Central Mich. - NEW - 239
Do NOT be a victimIdentity Theft Back to home pageMillions of Americans fall prey to identity theft every year. Last year estimates show that identity theft has affected 1 in 8 U.S. adults. Identity theft is:Running up bil
Central Mich. - EDU - 069
Lisa Miller Prepared for First Grade Math Practice04/30/09 Addition 1Addition Review Before you try some adding problems you will see some examples to help you remember how to add.04/30/09Addition2Example Problem # 1+ 1 frog + 1 frog = =
Central Mich. - EDU - 290
Lisa Miller Prepared for First Grade Math Practice04/30/09 Addition 1Addition Review Before you try some adding problems you will see some examples to help you remember how to add.04/30/09Addition2Example Problem # 1+ 1 frog + 1 frog = =
Central Mich. - ENG - 326
Literary Dimensions of Film Course ReviewLiterary/Film Terms Point of View Objective Subjective Conventions Allusions Genre Flashback Intertextuality Narration (Literature) Voice-Over (Film) First Person Narrator Third Person Narrat
Central Mich. - ENG - 637
Scientific Style IThe eddy diffusion coefficient is estimated as a function of altitude, separately for the Jovian troposphere and mesosphere. The growth-rate and motion of particles is estimated for various substances: the water clouds are probably
Grinnell - CS - 302
CSC302 2006S, Class 30: SEQUELAdmin:* Questions on the exam?* Broken record: Time for serious grading seems to be an impossibility.* Reading for Monday: Kowalski = Algorithm = Logic + Control. Famous paper : Program = Algorithms + Data Structu
Grinnell - CSC - 161
#P# likes to #V# when the #N# is #A#.
Grinnell - CSC - 152
Jill likes to _verb_ with Java because she thinks that Java is _adjective_.When things go well, Jill is _adjective_.When things go badly, she yells "_exclamation_!"