PL Recitation 9/21/2010

Similar documents
Programming Languages

Every language has its own scoping rules. For example, what is the scope of variable j in this Java program?

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

Scope. CSC 4181 Compiler Construction. Static Scope. Static Scope Rules. Closest Nested Scope Rule

Final thoughts on functions F E B 2 5 T H

LECTURE 14. Names, Scopes, and Bindings: Scopes

Chapter 5. Names, Bindings, and Scopes

Programming Languages Third Edition. Chapter 7 Basic Semantics

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility


Introduction to C++ with content from

Type Bindings. Static Type Binding

Programming Languages

Programming for Engineers in Python. Recitation 1

Names, Scopes, and Bindings II. Hwansoo Han

Lecture 10. Memory in Python

Names, Bindings, Scopes

names names identifiers variables subroutines constants

The Big Picture. Linker. Module 1. Module 2. One Module. Module 3. Module 4

CA Compiler Construction

Lecture #5 Kenneth W. Flynn RPI CS

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

The role of semantic analysis in a compiler

Chapter 9 Subprograms

Compiler Design Spring 2018

1: Introduction to Object (1)

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Data Structures (list, dictionary, tuples, sets, strings)

Object Oriented Programming

Chapter 1. Fundamentals of Higher Order Programming

Topic III. LISP : functions, recursion, and lists References: Chapter 3 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

Object Oriented Design

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

PROGRAMMING IN C++ COURSE CONTENT

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

Programming for Engineers in Python. Autumn

CSC207 Week 4. Larry Zhang

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

CSC 148 Lecture 3. Dynamic Typing, Scoping, and Namespaces. Recursion

Iterative Languages. Scoping

New York University Computer Science Department Courant Institute of Mathematical Sciences

Common Lisp in the Wild

Java Object Oriented Design. CSC207 Fall 2014

Data Structures using OOP C++ Lecture 3

Chapter 5 Names, Binding, Type Checking and Scopes

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Programming Languages: Lecture 11

Overview of the Ruby Language. By Ron Haley

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

ECE573 Introduction to Compilers & Translators

Chapter 3:: Names, Scopes, and Bindings

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Type-checking on Heterogeneous Sequences

INF4820. Common Lisp: Closures and Macros

CS 415 Midterm Exam Spring 2002

G Programming Languages - Fall 2012

Concepts of Programming Languages

x = e Python tries to avoid overwrites i Python tries to avoid overwrites next Monday Programming Assignment #7 on Prolog quarter Assignment Revisited

Environments

In fact, as your program grows, you might imagine it organized by class and superclass, creating a kind of giant tree structure. At the base is the

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1

COS 140: Foundations of Computer Science

CS Exam #1-100 points Spring 2011

Run Time Environments

Programming Languages

Next: What s in a name? Programming Languages. Data model in functional PL. What s in a name? CSE 130 : Fall Lecture 13: What s in a Name?

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Programming Languages 2nd edition Tucker and Noonan"

Robot Programming with Lisp

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

CLIP - A Crytographic Language with Irritating Parentheses

Functional Programming. Big Picture. Design of Programming Languages

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY ACADEMIC YEAR (ODD SEM)

Object Model. Object Orientated Analysis and Design. Benjamin Kenwright

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

TypeScript. Types. CS144: Web Applications

Principles of Compiler Construction ( )

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention

Compiler construction

CS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors

CS415 Compilers. Procedure Abstractions. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Object Oriented Programming

Allegro CL Certification Program

Runtime Environments I. Basilio B. Fraguela

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table

VARIABLES AND TYPES CITS1001

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

C++ (Non for C Programmer) (BT307) 40 Hours

Mobile Forms Integrator

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

GMU SWE 443 Software Architecture Spring Lab 2: Implicit-invocation System. Sousa Discuss Feb 23, due March 8

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Programming Languages

Transcription:

PL Recitation 9/21/2010

Recitation Leader Joanna Gilberti Email: jlg204@cs.nyu.edu Office: WWH, Room 328 Web Site: http://cims.nyu.edu/~jlg204/ courses/pl/index.html (linked from main course Web site)

Homework Submission Guidelines Submit all homework to me via email Email subject: PL firstname lastname homework # (EXAMPLE: PL Joanna Gilberti Homework 1 ) Use file naming convention on all attachments: firstname_lastname_hw_# (example: "joanna_gilberti_hw_1") Include your name on all files (including source code)

Homework Submission Procedure All homework assignments are to be submitted electronically on the day they are due. Homework assignments submitted one day late from the due date will be penalized by 50%. Homework assignments will not be accepted if two days late (solutions will be posted) I will provide an email notification ( received or late ) upon receipt of homework.

What s Covered in Recitation Homework solutions. Questions on the assignments. For additional questions on assignments, it is best to contact me via email. I will hold office hours (time will be posted on the recitation Web site). Run sample problems that demonstrate concepts covered in class.

Homework 1: Clarification Question 2 must provide actual statements. It is not sufficient to just provide a count. Question 5 provide a sample whenever possible to justify your answer (don t simply answer yes or no, for example).

Binding & Scoping Concepts

Binding Binding - the operation of associating two things, like a name and the entity it represents. Binding time - the moment when the binding is performed (compilation, execution, etc). Static binding - dynamic binding. Refers to compilation vs. runtime.

Binding Time Language design - fundamental aspects of the language, built-in functions, keywords. Language implementation - details such as the size of each type, runtime exceptions. Programming - algorithms, design of data structures. Compilation - mapping between higher-level constructs and machine code, static data. Linking - layout of program in memory. Load - virtual addresses, dynamic libraries. Runtime - virtual functions, values to variables, many more.

Scope & Rules Scope of a binding - the textual region of the program in which a binding is active. Scope - sometimes a region of a program of maximal size in which no binding changes scope.

Scope of a Binding Usually the scope of a binding is determined statically, meaning at compilation time. When a function is called that has a local variable, the binding between the variable name and the instance of the variable local to the call is created. Any previous bindings for that same variable name are deactivated in the process (or hidden). When the function call ends, the previous binding for the name is restored.

Static (Lexical) vs. Dynamic Scopes Static scope - when the scope of a binding is determined during compilation. Current binding - the matching declaration whose block most closely surrounds the point in the program where the name is mentioned. Dynamic scope - Bindings that are defined at runtime. They depend on the order in which functions are called. Current binding - the one encountered the most recently during the execution and that has not yet been destroyed.

Dynamic Scope - Lisp (defvar y 3) ; y is global (defun f (x) (+ x y)) ; we think that f uses global y (f 10) ; => 13 (defun g () (let ((y 4) (a 1)) (f a))) (g) ; => 5 ; actually, f does not use global y

Static Scope - Python Python appears to have dynamic scope, but, in fact, has static scope. Example: pi = 3.1415 def area(r): return pi*r*r area(10) # 314.1500 pi = 3 Area(10) # 300 * in the second call to Area(), pi is changed.

Static Scope - Python Another example: pi = 3.1415 pi_holder = 10 def create_area(): pi_holder = pi # local pi_holder def area(r): return pi_holder*r*r return area area = create_area() area(10) # 314.15 pi_holder # Still 10 pi_holder = 3 area(10) # Still 314.15

Static Scope - Python Analysis: The first example works, but is problematic. However, in the second example, when we declare pi_holder=10, which: (1) pi_holder inside of create_area() is a local variable; (2) the local pi_holder is in area s scope, thus changing the value of pi_holder does not affect it.

Static Scope - Python A third example (re-write of the second python example): pi = 3.1415 def create_area(pi = pi): def area(r): return pi*r*r return area area = create_area() area(10) #314.15 pi = 3 area(10) #314.15 ** Python has static scoping! Python functions inherit the surrounding scope, and so to prevent this, you would need to wrap your function definition inside another function that copies in the values you need into its local variables.