Cs1120 Fall 2009 David Evans Lecture 18: Changing State Sounds of Colossus:

Slides:



Advertisements
Similar presentations
Class 3: Rules of Evaluation David Evans cs1120 Fall 2009.
Advertisements

Class 21: Imperative Programming University of Virginia cs1120 David Evans.
Cs1120 Fall 2009 David Evans Lecture 15: Running Practice.
Cs1120 Fall 2009 David Evans Lecture 16: Power Analysis.
Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 39: Lambda Calculus.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 18: The Story So Far.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 16: Quicker Sorting.
CSE341: Programming Languages Lecture 15 Mutation, Pairs, Thunks, Laziness, Streams, Memoization Dan Grossman Fall 2011.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 31: Types of Types.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 28: Implementing Interpreters.
 The CCD sensor was invented in 1969 by Willard Boyle and George E. Smith of AT&T Bell Labs.  Originally intended as a memory device.
Cs1120 Fall 2009 David Evans Lecture 20: Programming with State.
Cs1120 Fall 2009 David Evans Lecture 19: Stateful Evaluation.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 5: Recursing Recursively Richard Feynman’s.
David Evans Class 15: Golden Ages and Astrophysics CS200: Computer Science University of Virginia Computer Science.
David Evans Class 13: Quicksort, Problems and Procedures CS150: Computer Science University of Virginia Computer Science.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 2: Orders of Growth
15 October 2003Computer Science1 David Evans ComputerScience.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
Computer and Information Literacy: A Moving Target Jack Beidler James R. Sidbury University of Scranton Scranton, PA (717)
Lecture 31: Laziness University of Virginia cs1120 Fall 2009 David Evans.
Lecture 8: The Meaning of Life, Searching for Truth and The Stuff Primitives are Made Of (and a smattering of Quantum Physics) David Evans
David Evans CS150: Computer Science University of Virginia Computer Science Class 33: Computing with Photons From The.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
David Evans CS200: Computer Science University of Virginia Computer Science Class 17: Mutation M. C. Escher, Day and Night.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 9: Strange Loops and Sinister Repeaters.
Class 37: Secret of Life CS200: Computer Science
David Evans Class 21: The Story So Far (Quicksort, Continuing Golden Ages) CS200: Computer Science University of Virginia.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
David Evans Lecture 13: Astrophysics and Cryptology CS200: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Class 16: Mutation M. C. Escher, Day and Night.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 5: Recursing on Lists.
David Evans Class 16: NP-Completeness / The Story so Far CS150: Computer Science University of Virginia Computer Science.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Mutation M. C. Escher, Day and.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 9: Of On and Off Grounds Sorting Coffee.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 15: Intractable Problems (Smiley.
Fall 2008Programming Development Techniques 1 Topic 17 Assignment, Local State, and the Environment Model of Evaluation Section 3.1 & 3.2.
Class 28: Interpreters cs1120 Fall 2009 David Evans.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
Class 7: List Procedures David Evans cs1120 Fall 2009.
Lecture 3: Rules of Evaluation CS150: Computer Science
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 4: Programming with Data.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 8: Recursing Recursively Richard Feynman’s.
CS 152: Programming Language Paradigms February 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
David Evans CS150: Computer Science University of Virginia Computer Science Class 32: Computability in Theory and Practice.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 8: Cons car cdr sdr wdr.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 9: Recursing Recursively Richard Feynman’s.
(Thunking about Thunks)
Lecture 4: Metacircles Eval Apply David Evans
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2017.
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Lecture 7: List Recursion CS200: Computer Science
Class 19: Think Globally, Mutate Locally CS150: Computer Science
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2013.
Lecture 6: Programming with Data CS150: Computer Science
David Evans Lecture 9: The Great Lambda Tree of Infinite Knowledge and Ultimate Power CS200: Computer Science University.
Lecture 28: Types of Types
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2016.
Lecture 26: The Metacircular Evaluator Eval Apply
Lecture 9: The Great Lambda Tree of Knowledge and Power
Dan Grossman / Eric Mullen Autumn 2017
Lecture 3: Rules of Evaluation CS200: Computer Science
Lecture 8: Recursing Lists CS150: Computer Science
Lecture 23: Computability CS200: Computer Science
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2019.
Lecture 25: The Metacircular Evaluator Eval Apply
Presentation transcript:

cs1120 Fall 2009 David Evans Lecture 18: Changing State Sounds of Colossus:

Menu Computing with Electrons The Story So Far Introduction Mutation

Yesterday’s Nobel Prize in Physics Charles K. Kao Bell Labs, New Jersey Standard Telecommunication Laboratories, United Kingdom fiberoptics: using light to transmit data Willard S. BoyleGeorge E. Smith Charge-Coupled Device (1969)

Charge-Coupled Device (CCD)

Moving Collected Charge Photocell Light Silicon substrate: not powered, conducts well powered, does not conduct Voltage Photocell: photoelectric effect (Einstein’s 1921 nobel prize): photons hit silicon plate and knock out electrons (more light, more electrons)

CCDs Today Sloan Digital Sky Survey (1998): array of 30, ~4Mpixel CCDs

cs1120 Story so Far

Course Roadmap Synthesis Analysis Ch 2: LanguageCh 3: ProgrammingCh 4: ProceduresCh 5: Data Ch 6: Machines Ch 7: Cost Ch 8: Sorting and Searching PS5, Ch 9: StatePS6, Ch 10: Objects Ch 13: Intractability PS7, Ch 11: Interpreters Ch 12: Computability PS8, 9: Building Web Applications You are here Ch 1: Computing

Computer Science: cs1120 so far How to describe information processes by defining procedures (Chapters 3, 4, 5) – Programming with procedures, lists, recursion How to predict properties about information processes (Chapter 6, 7) – Predicting how running time grows with input size How to efficiently implement information processes (not much on this) – Chapter 3 (rules of evaluation) – Chapter 6 (machines)

cs1120 Upcoming How to describe information processes by defining procedures – Programming with state (Ch 9), objects (Ch 10), languages (Ch 11) How to predict properties about information processes – Are there problems which can’t be solved by algorithms? (Ch 12) – What is the fastest process that can solve a given problem? (Ch 13) How to efficiently implement information processes – How to implement a Scheme interpreter (Ch 11)

The Liberal Arts Trivium (3 roads) language Quadrivium (4 roads) numbers GrammarRhetoricLogicArithmetic Geometry Music Astronomy From Chapter 1/Lecture 1:

Liberal Arts Checkup Grammar: study of meaning in written expression Rhetoric: comprehension of verbal and written discourse Logic: argumentative discourse for discovering truth Arithmetic: understanding numbers Geometry: quantification of space Music: number in time Astronomy BNF, RTN, rules of evaluation for meaning Not much yet…interfaces between components (PS6-9), program and user (PS8-9) Rules of evaluation, if, recursive definitions adding, multiplying with simple logic representing numbers, more in Nov Curves as procedures, fractals (PS3) Yes, listen to “Hey Jude!” Soon: read Neil deGrasse Tyson’s essay Trivium Quadrivium

Introducing Mutation

Evaluation Rule 2: Names A name expression evaluates to the value associated with that name. > (define two 2) > two 2 From Lecture 3: This has been more-or-less okay so far, since the value associated with a name never changes...

Names and Places A name is not just a value, it is a place for storing a value. define creates a new place, associates a name with that place, and stores a value in that place x: 3 (define x 3)

Bang! set! (“set bang”) changes the value associated with a place > (define x 3) > x 3 > (set! x 7) > x 7 x: 3 7

set! should make you nervous > (define x 2) > (nextx) 3 > (nextx) 4 > x 4 Before set! all procedures were functions (except for some with side-effects). The value of (f) was the same every time you evaluate it. Now it might be different!

Defining nextx (define (nextx) (set! x (+ x 1)) x) (define nextx (lambda () (begin (set! x (+ x 1)) x)))) syntactic sugar for

Evaluation Rules > (define x 3) > (+ (nextx) x) 7 or 8 > (+ x (nextx)) 9 or 10 DrScheme evaluates application subexpressions left to right, but Scheme evaluation rules allow any order.

Mutable Cons Cell mcons – creates a mutable cons cell (mcar m) – first part of a mutable cons cell (mcdr m) – second part of a mutable cons cell 1 2 (mcons 1 2)

set-mcar! and set-mcdr! (set-mcar! p v) Replaces the car of mutable cons p with v. (set-mcdr! p v) Replaces the cdr of mutable cons p with v. These should scare you even more then set!!

> (define pair (mcons 1 2)) > pair (1. 2) pair: 1 2

> (define pair (mcons 1 2)) > pair {1. 2} > (set-mcar! pair 0) > (mcar pair) 0 > (mcdr pair) 2 > (set-mcdr! pair 1) > pair {0. 1} pair:

Impact of Mutation We will need to revise our evaluation rules for names and application expressions: substitution model of evaluation no longer works since values associated with names change We need to be much more careful in our programs to think about when things happen: order matters since values change

Charge PS5: posted now, due next Wednesday Read Chapter 9 Friday: return Exam 1, Revising our Evaluation Rules to handle mutation Monday, 19 October