Scoping and Binding of Variables

Slides:



Advertisements
Similar presentations
For(int i = 1; i
Advertisements

Some non-recursive tricks. The Lambda expression. More on Let, Let*, apply and funcall.
Variables, Environments and Closures. Overview We will Touch on the notions of variable extent and scope Introduce the notions of lexical scope and.
Elements of Lambda Calculus Functional Programming Academic Year Alessandro Cimatti
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Chapter 5 ( ) of Programming Languages by Ravi Sethi
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
1 Scheme Scheme is a functional language. Scheme is based on lambda calculus. lambda abstraction = function definition In Scheme, a function is defined.
Lifetime “The lifetime of a variable is the time during which the variable is bound to a specific memory location.” [p. 219] “…the lifetime of a variable.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
Introduction Even though the syntax of Scheme is simple, it can be very difficult to determine the semantics of an expression. Hacker’s approach: Run it.
Rutgers University Relational Calculus 198:541 Rutgers University.
Block Scope By Greg Butler Purpose The purpose of this presentation is to familiarize the student with the concept of variable scope, as it relates to.
CSE 190M Extra Session #5 JavaScript scope and closures slides created by Marty Stepp
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Scope.
CS 152: Programming Language Paradigms February 24 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Bindings and scope  Bindings and environments  Scope and block structure  Declarations Programming Languages 3 © 2012 David A Watt, University.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
Cs7100(Prasad)L8Proc1 Procedures. cs7100(Prasad)L8Proc2 Primitive procedures  etc User-defined procedures –Naming a sequence of operations.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
Types and Programming Languages Lecture 6 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Variables, Environments and Closures. Overview Touch on the notions of variable extent and scope Introduce the notions of lexical scope and dynamic.
PPL Lecture 3 Slides by Yaron Gonen, based on slides by Daniel Deutch and lecture notes by Prof. Mira Balaban.
JavaScript scope and closures
Comp 311 Principles of Programming Languages Lecture 4 The Scope of Variables Corky Cartwright September 3, 2008.
CS345 Project Presentation Language: H-- Mikhail Iakhiaev.
CSE 130 : Spring 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 5: Functions and Closures.
Cs3180 (Prasad)L156HOF1 Higher-Order Functions. cs3180 (Prasad)L156HOF2 Equivalent Notations (define (f x y) (… body …)) = (define f (lambda (x y) (…
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Message Passing: Alternative to Generics data is “active” — knows how to compute dispatch on operation (define (rat (n ) (d )) (method ((op )) (cond ((=
Procedure Definitions and Semantics Procedures support control abstraction in programming languages. In most programming languages, a procedure is defined.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Converting arbitrary wffs to CNF A wff is in prenex form iff it consists of a string of quantifiers (called a prefix) followed by a quantifier free formula.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Advanced Programming in C
Lecture 9 Symbol Table and Attributed Grammars
Relational Calculus Chapter 4, Section 4.3.
Functional Programming
Names and Attributes Names are a key programming language feature
Variables, Environments and Closures
Building Java Programs
CSCI 161 – Introduction to Programming I William Killian
Corky Cartwright January 18, 2017
Scope of Variables.
Stack Memory 2 (also called Call Stack)
Variables, Environments and Closures
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
FP Foundations, Scheme In Text: Chapter 14.
CSC 253 Lecture 7.
3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))
Binding Times Binding is an association between two things Examples:
Chapter 1 Review: BNF Grammar for lists:
Let bindings Motivation: Functions without local variables can be poor style and/or really inefficient. Syntax: let b1 b2 ... bn in e end where each bi is.
UNIT V Run Time Environments.
CSE 341 Lecture 27 JavaScript scope and closures
Building Java Programs
CSE 3302 Programming Languages
CSE 341 Lecture 11 b closures; scoping rules
Principles of Programming Languages
Building Java Programs
Chapter 3 Discussion Pages
Presentation transcript:

Scoping and Binding of Variables A variable can appear as a declaration or a reference. Declaration: int f(int x, int y) { int a; (lambda (x y) (let((a ...

Scoping and Binding of Variables Reference: (lambda (x y) (let ( (a 4) ) (+ a (* x y))))

Scoping and Binding of Variables A variable reference is said to be bound by a declaration: (lambda (x y) (let ( (a 4) ) (+ a (* x y))))

Scoping and Binding of Variables Binding takes place within a scope. Scope of x, y: (lambda (x y) (let ( (a 4) ) (+ a (* x y))))

Scoping and Binding of Variables Scope of a: (lambda (x y) (let ( (a 4) ) (+ a (* x y))))

Scoping and Binding of Variables Scope in Scheme (and most languages) is static. Means we can determine scope by looking at code. But can get tricky with nesting! (let ((a 3)) (let ((a (+ a a))) a))

Free and Bound Variables Variable x, expression E x occurs free in E iff there is some use of x in E that is not bound by any declaration of x in E x occurs bound in E iff there is some use of x in E that is bound by any declaration of x in E E = (lambda (a) (* a b))

Free and Bound Variables in English! John hates him. // must be free John hates himself. // must be bound John said that Bill hates him. // free or bound * Himself hates John. // reference before declaration