Changing Data: (Continued)

Slides:



Advertisements
Similar presentations
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Advertisements

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.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Metacircular Evaluation SICP Chapter 4 Mark Boady.
1/25 Concurrency and asynchronous computing How do we deal with evaluation when we have a bunch of processors involved?
CSC 160 Computer Programming for Non-Majors Lecture #10: Conditionals I Prof. Adam M. Wittenstein
Hand Evals in DrRacket Hand evaluation helps you learn how Racket reduces programs to values.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
SchemeCOP Introduction to Scheme. SchemeCOP Scheme Meta-language for coding interpreters –“ clean ” semantics Scheme = LISP + ALGOL –simple.
Fall 2008Programming Development Techniques 1 Topic 18 Environment Model of Evaluation Section 3.2 Acknowledgement: This lecture (and also much of the.
Data Structures: Binary Trees CMSC Introduction to Computer Programming October 28, 2002.
Assignment: Changing Data CMSC Introduction to Computer Programming November 1, 2002.
1 Subt. model interpreter: Structure of the interpreter ASP Derived expressions Core Test Data structures Utils A racket lib Proc / Primitive-Proc. Global.
D x (c) = 0 D x (x) = 1 D x (y) = 0 for y an independent variable D x (u+v) = D x (u) + D x (v) D x (uv) = u D x (v) + v D x (u) D x (u n ) = nu n-1 D.
Mutual Recursion: Web pages CMSC Introduction to Computer Programming November 25, 2002.
Abstraction: Procedures as Parameters CMSC Introduction to Computer Programming October 14, 2002.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 23: Programming with Objects.
1 Lecture 14: Assignment and the Environment Model (EM)
Lecture on Set! And Local CS 2135 Copyright Kathi Fisler, 2002 This material requires Advanced Language Level.
Fall 2008Programming Development Techniques 1 Topic 16 Assignment and Local State Section 3.1.
1 Programming Languages (CS 550) Lecture 4 Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Scope: What’s in a Name? CMSC Introduction to Computer Programming October 16, 2002.
9-October-2002cse MoreLambda © 2002 University of Washington1 More Lambda CSE 413, Autumn 2002 Programming Languages
Message Passing: Alternative to Generics data is “active” — knows how to compute dispatch on operation (define (rat (n ) (d )) (method ((op )) (cond ((=
CS61A Lecture Colleen Lewis 1. Clicker poll Are you in a two person group for project 4? A)Yes – I have my partner B)No – I plan to work.
1 Topic #3: Lambda CSE 413, Autumn 2007 Programming Languages.
ME 120: User-defined functions: average analog input reading Arduino Programming – Part 5: User-defined functions ME 120 Mechanical and Materials Engineering.
Meta-Circular Evaluation CMSC Introduction to Computer Programming November 20, 2002.
Operational Semantics of Scheme
Lecture #5 מבוא מורחב.
Lecture 4: Metacircles Eval Apply David Evans
Data Abstraction: Sets
6.001 SICP Variations on a Scheme
6.001 SICP Object Oriented Programming
6.001 SICP Compilation Context: special purpose vs. universal machines
Introduction to Scheme
Chapter 15 – Functional Programming Languages
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Material in the textbook on pages
COP4020 Programming Languages
Env. Model Implementation
Original material by Eric Grimson
Introduction to Functional Programming in Racket
Nondeterministic Evaluation
Lecture #5 מבוא מורחב.
The Metacircular Evaluator
Dynamic Scoping Lazy Evaluation
The Metacircular Evaluator
topics three representations entity relationship diagram object model
3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))
Lecture 26: The Metacircular Evaluator Eval Apply
6.001 SICP Further Variations on a Scheme
Explicit Application of Procedures, and Explicit Evaluation
Chapter 1 Review: BNF Grammar for lists:
Streams, Delayed Evaluation and a Normal Order Interpreter
Lecture #9 מבוא מורחב.
Lecture 12: Message passing The Environment Model
Lecture 13 - Assignment and the environments model Chapter 3
6.001 SICP Variations on a Scheme
Introduction to Functional Programming in Racket
Lecture 14: The environment model (cont
6.001 SICP Interpretation Parts of an interpreter
Assignments and Procs w/Params
Lecture 13: Assignment and the Environment Model (EM)
topics interpreters meta-linguistic abstraction eval and apply
More Scheme CS 331.
Principles of Programming Languages
Lecture 25: The Metacircular Evaluator Eval Apply
Bringing it all Together: Family Trees
Presentation transcript:

Changing Data: (Continued) CMSC 11500 Introduction to Computer Programming November 4, 2002

Roadmap Recap: Assignment & Data with state Topical Example: Voting! Variables to capture state Multiple state variables: voter types Actions: Update poll stats (view results) What’s the same? different? Encapsulation Scope Hand-evaluation

Recap: Modeling State Data objects change over time Bank account, traffic light, Represent with variable(s) that change Mechanism: (set! var expr) Changes value to var to result of eval expr Supporting mechanism: (begin exp1 exp2 … expn): Evaluates all expressions: returns value of last

Defining a Poll What state captures a poll? What actions? Number of voters Number of voters in each category: For, against, undecided What actions? Add in new votes as come in Update Report current levels

What’s a vote? vote-type is 1) ‘for 2) ‘against 3) ‘undecided

Make-poll Contract: Purpose: -> (vote-type number -> (listof number)) Purpose: ;; To setup procedure to update standings Effect: update voters-for,against, undecided

Make-poll (define (make-poll) (let ((voters-for 0) (voters-against 0) (voters-undecided 0)) (lambda (vote-class new-votes) (let ((total-votes (+ new-votes voters-for voters-against voters-undecided))) (cond ((eq? vote-class 'for) (set! voters-for (+ voters-for new-votes))) ((eq? vote-class 'against) (set! voters-against (+ voters-against new-votes))) ((eq? vote-class 'undecided) (set! voters-undecided (+ voters-undecided new-votes))) (else (error "bad vote type"))) (list (/ voters-for total-votes) (/ voters-against total-votes) (/ voters-undecided total-votes))))))

Identity (define contest1 (make-poll)) (define contest2 contest1) Contest1 & contest2 “same” Use same state variables Contest3: Different Also poll – no shared state values

Encapsulation Local definition Defining as result shares variables State variables encapsulated in procedure Distinct for each invocation of make-poll Defining as result shares variables Separate invocation -> separate states

Summary Data objects change over time Capture in state variables