Midterm Review John Mitchell CS 242. Midterm uThurs Nov 7, 7-9PM Terman Aud Closed book uClass schedule Thurs Oct 31, Tues Nov 5 – topics not on midterm.

Slides:



Advertisements
Similar presentations
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Advertisements

1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Programming Languages and Paradigms
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Midterm Review John Mitchell CS Topics uJavaScript uBlock structure and activation records uExceptions, continuations uTypes and type inference.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Chapter 10 Implementing Subprograms. Copyright © 2012 Addison- Wesley. All rights reserved. 1-2 Chapter 10 Topics The General Semantics of Calls and Returns.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Cse321, Programming Languages and Compilers 1 6/12/2015 Lecture #17, March 12, 2007 Procedure Abstraction, Name Spaces, Scoping Rules, Activation Records,
Dr. Muhammed Al-Mulhem ICS Chapter 7 Scope, Functions, and Storage Management.
1 Names, Scopes and Bindings. 2 Names Kinds of names Kinds of names Variables, functions, classes, types, labels, blocks, operators, tasks, etc. Variables,
Run time vs. Compile time
Catriel Beeri Pls/Winter 2004/5 environment 68  Some details of implementation As part of / extension of type-checking: Each declaration d(x) associated.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Scope, Function Calls and Storage Management John Mitchell CS
Chapter 9: Subprogram Control
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Closure and Environment Compiler Baojian Hua
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Scope, Function Calls and Storage Management John Mitchell CS
Slide 1 Vitaly Shmatikov CS 345 Scope and Activation Records.
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
Lisp John Mitchell CS 242 Reading: Chapter 3 Homework 1: due Oct 3.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Chapter TwelveModern Programming Languages1 Memory Locations For Variables.
ISBN Chapter 10 Implementing Subprograms.
Final Review TA Review Session Final Exam CS 242 Monday Dec 10
Slide 1 Vitaly Shmatikov CS 345 Introduction to Scheme.
CS 2104 Prog. Lang. Concepts Subprograms
Runtime Environments Compiler Construction Chapter 7.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Types John Mitchell CS 242. Type A type is a collection of computable values that share some structural property. uExamples Integers Strings int  bool.
10/16/2015IT 3271 All about binding n Variables are bound (dynamically) to values n values must be stored somewhere in the memory. Memory Locations for.
Basic Semantics Associating meaning with language entities.
CS112: Structure of Programming Languages A smorgasbord of topics in programming languages including programming paradigms and syntax, semantics, implementation.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 8.
Programming Languages and Paradigms Imperative Programming.
Types John Mitchell CS 242 Reading: Chapter 6. Announcements uHomework 1 due today Turn in at the end of class, OR Turn in by 5PM to the homework drop.
COMP3190: Principle of Programming Languages
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Lisp John Mitchell CS 242. Lisp, 1960 uLook at Historical Lisp Perspective –Some old ideas seem old –Some old ideas seem new Example of elegant, minimalist.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Programming Languages: Design, Specification, and Implementation G Rob Strom September 21, 2006.
Lisp John Mitchell CS 242 Reading: Chapter 3 Homework 1: due Oct 6.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
Types John Mitchell CS 242. Type A type is a collection of computable values that share some structural property. uExamples Integers Strings int  bool.
Cs7120 (Prasad)L1-FP-HOF1 Functional Programming Basics Correctness > Clarity > Efficiency.
Scope, Function Calls and Storage Management John Mitchell CS Reading: Chapter 7, Concepts in Programming Languages.
ISBN Chapter 12 Support for Object-Oriented Programming.
Heath Carroll Bill Hanczaryk Rich Porter.  A Theory of Type Polymorphism in Programming ◦ Robin Milner (1977)  Milner credited with introducing the.
CS314 – Section 5 Recitation 9
Functional Programming
Names and Attributes Names are a key programming language feature
CS 326 Programming Languages, Concepts and Implementation
CS 326 Programming Languages, Concepts and Implementation
Names, Binding, and Scope
FP Foundations, Scheme In Text: Chapter 14.
Lecture 12: Message passing The Environment Model
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CS 242 Types John Mitchell.
Scope, Function Calls and Storage Management
More Scheme CS 331.
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Midterm Review John Mitchell CS 242

Midterm uThurs Nov 7, 7-9PM Terman Aud Closed book uClass schedule Thurs Oct 31, Tues Nov 5 – topics not on midterm Thurs Nov 7 – optional review during lecture time uHomework and Sample Midterm Homework due Tues Nov 5 as usual; no late HW HW 5 solutions available Nov 5 Sample exam on web now – previous year’s handouts Sample exam solutions on web Tues Nov 5

Topics uLisp, 1960 uFundamentals lambda calculus denotational semantics functional prog uML and type systems uBlock structure and activation records uExceptions and continuations uModularity uOO concepts encapsulation dynamic lookup subtyping inheritance uSimula and Smalltalk uC++ uJava uConcurrency

Lisp Summary uSuccessful language Symbolic computation, experimental programming uSpecific language ideas  Expression-oriented: functions and recursion  Lists as basic data structures  Programs as data, with universal function eval  Stack implementation of recursion via "public pushdown list"  Introduced garbage collection

Differentiation in Lisp (define diff (lambda (y x) (cond ( (atom y) (if (eq x y) 1 0)) ;; y is a var or constant ( ;; expression y is sum (eq (car y) '+) ;; (A + B)' = A' + B' (cons '+ (maplist (cdr y) (lambda (z) (diff (car z) x))))) ( ;; expression is product (eq (car y) '*) ;; (A * B)' = A'B'C + B'A (cons '+ (maplist (cdr y) (lambda (z) (cons '* (maplist … ))))))))))))

Fundamentals uGrammars, parsing uLambda calculus uDenotational semantics uFunctional vs. Imperative Programming Why don’t we use functional programming? Is implicit parallelism a good idea? Is implicit anything a good idea?

Declarations and reduction function f(x) return x+2 end; f(5); block bodydeclared function ( f. f(5)) ( x. x+2)  ( x. x+2) (5)  5+2  7 (if we add reduction rules for addition)

Initialize-before-use semantics Values = {OK, bad}) State = { error }  (Variables  {init, uninit}) E[[ c ]](s) = OK for c any symbol not a variable E[[ v ]](s) = if s(v)= init then OK else bad C[[ x:= e ]](s) = if E[[e]](s) = OK then modify(s,x, init) else error C[[ x:= 0; y:= x+1 ]](s) = state s’ with s’(x)=s’(y)=init C[[ x:= y; … ]](s) = error if s(y) = uninit

ML uTyped programming language uIntended for interactive use uCombination of Lisp and Algol-like features Expression-oriented Higher-order functions Garbage collection Abstract data types Module system Exceptions uGeneral purpose non-C-like, non-OO language

Use of ML in this course uSurvey a modern procedural language uDiscuss general programming languages issues Types and type checking –General issues in static/dynamic typing –Type inference –Polymorphism and Generic Programming Memory management –Static scope and block structure –Function activation records, higher-order functions Control –Force and delay –Exceptions –Tail recursion and continuations

Types and Type Inference uType safety Can use compile-time or run-time typing Cannot have dangling pointers uType inference Compute types from the way symbols are used Know how algorithm works (for simple examples) Know what an ML polymorphic type means - fun f(g,x) = g(g(x)); > val it = fn : (t  t)*t  t Polymorphism different from overloading

fun sum(x) = x +  t v w y z :r :s u r  t = int  (int  int) r  u = int  (int  int) u = int  v s = v  w t = w  y z = r  y s = z v = int w = int … s = v  w = int  int

Block structure and storage mgmt uBlock-structured languages and stack storage uIn-line Blocks activation records storage for local, global variables uFirst-order functions parameter passing tail recursion and iteration uHigher-order functions deviations from stack discipline language expressiveness => implementation complexity

Activation record for static scope uControl link Link to previous (calling) block uAccess link Link to record of enclosing block uReturn address Next instruction after return uReturn-result address Place to put return value uParameters Set when function called uLocal variables uIntermediate results Control link Local variables Intermediate results Environment Pointer Parameters Return address Return-result addr Access link

Complex nesting structure int x=1; function g(z) = x+z; function f(y) = { int x = y+1; return g(y*x) }; f(3); function m(…) { int x=1; … function n( … ){ function g(z) = x+z; … { … function f(y) { int x = y+1; return g(y*x) }; … f(3); … } … n( … ) …} … m(…) Simplify to Simplified code has same block nesting, if we follow convention that each declaration begins a new block.

Function Results and Closures c access Code for counter Code for mk_counter c(2) access inc2 1 mk_counter(1) count init1 access counter mk_c Call changes cell value from 1 to 3 3 {int  int mk_counter (int init) { int count = init; int counter(int inc) { return count+=inc;} } int  int c = mk_counter(1); print c(2) + c(2); }

Summary of scope issues uBlock-structured lang uses stack of activ records Activation records contain parameters, local vars, … Also pointers to enclosing scope uSeveral different parameter passing mechanisms uTail calls may be optimized uFunction parameters/results require closures Closure environment pointer used on function call Stack deallocation may fail if function returned from call Closures not needed if functions not in nested blocks

Control uStructured Programming Go to considered harmful uExceptions “structured” jumps that may return a value dynamic scoping of exception handler uContinuation Function representing the rest of the program Generalized form of tail recursion

General Suggestions uReview your notes and the reading assignments uLook over homework uDo the practice midterm uRelax