CS61A Lecture 18. Amir Kamil UC Berkeley March 4, 2013

Size: px
Start display at page:

Download "CS61A Lecture 18. Amir Kamil UC Berkeley March 4, 2013"

Transcription

1 CS61A Lecture 18 Amir Kamil UC Berkeley March 4, 2013

2 Announcements HW6 due on Thursday Trends project due tomorrow Ants project out

3 Persistent Local State The parent contains local state A function with a parent frame Every call changes the balance Example:

4 Non Local Assignment def make_withdraw(balance): """Return a withdraw function with a starting balance.""" def withdraw(amount): nonlocal balance Declare the name "balance" nonlocal if amount > balance: return 'Insufficient funds' balance = balance - amount return balance return withdraw Re bind balance where it was bound previously

5 Mutable Values and Persistent State

6 Mutable Values and Persistent State Mutable values can be changed without a nonlocal statement.

7 Mutable Values and Persistent State Mutable values can be changed without a nonlocal statement. Example:

8 Mutable Values and Persistent State Mutable values can be changed without a nonlocal statement. Name value binding cannot change Example:

9 Mutable Values and Persistent State Mutable values can be changed without a nonlocal statement. Mutable value can change Name value binding cannot change Example:

10 Creating Two Withdraw Functions Example:

11 Multiple References to a Withdraw Function Example:

12 The Benefits of Non Local Assignment

13 The Benefits of Non Local Assignment Ability to maintain some state that is local to a function, but evolves over successive calls to that function.

14 The Benefits of Non Local Assignment Ability to maintain some state that is local to a function, but evolves over successive calls to that function. The binding for balance in the first non local frame of the environment associated with an instance of withdraw is inaccessible to the rest of the program.

15 The Benefits of Non Local Assignment Ability to maintain some state that is local to a function, but evolves over successive calls to that function. The binding for balance in the first non local frame of the environment associated with an instance of withdraw is inaccessible to the rest of the program. An abstraction of a bank account that manages its own internal state.

16 The Benefits of Non Local Assignment Ability to maintain some state that is local to a function, but evolves over successive calls to that function. The binding for balance in the first non local frame of the environment associated with an instance of withdraw is inaccessible to the rest of the program. An abstraction of a bank account that manages its own internal state. Weasley Account $10

17 The Benefits of Non Local Assignment Ability to maintain some state that is local to a function, but evolves over successive calls to that function. The binding for balance in the first non local frame of the environment associated with an instance of withdraw is inaccessible to the rest of the program. An abstraction of a bank account that manages its own internal state. Weasley Account $10 Potter Account $1,000,000

18 Referential Transparency

19 Referential Transparency Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program.

20 Referential Transparency Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program. mul(add(2, mul(4, 6)), 3)

21 Referential Transparency Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program. mul(add(2, mul(4, 6)), 3) mul(add(2, 24 ), 3)

22 Referential Transparency Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program. mul(add(2, mul(4, 6)), 3) mul(add(2, 24 ), 3) mul( 26, 3)

23 Referential Transparency Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program. mul(add(2, mul(4, 6)), 3) mul(add(2, 24 ), 3) mul( 26, 3) Mutation is a side effect (like printing)

24 Referential Transparency Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program. mul(add(2, mul(4, 6)), 3) mul(add(2, 24 ), 3) mul( 26, 3) Mutation is a side effect (like printing) Side effects violate the condition of referential transparency because they do more than just return a value; they change the state of the computer.

25 Referential Transparency Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program. mul(add(2, mul(4, 6)), 3) mul(add(2, 24 ), 3) mul( 26, 3) Mutation is a side effect (like printing) Side effects violate the condition of referential transparency because they do more than just return a value; they change the state of the computer.

26 Referential Transparency Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program. mul(add(2, mul(4, 6)), 3) mul(add(2, 24 ), 3) mul( 26, 3) Mutation is a side effect (like printing) Side effects violate the condition of referential transparency because they do more than just return a value; they change the state of the computer.

27 A Mutable Container

28 A Mutable Container def container(contents):

29 A Mutable Container def container(contents): """Return a container that is manipulated by two functions.

30 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello')

31 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get()

32 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello'

33 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world')

34 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world') >>> get()

35 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world') >>> get() 'world'

36 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world') >>> get() 'world' """

37 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world') >>> get() 'world' """ def get():

38 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world') >>> get() 'world' """ def get(): return contents

39 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world') >>> get() 'world' """ def get(): return contents def put(value):

40 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world') >>> get() 'world' """ def get(): return contents def put(value): nonlocal contents

41 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world') >>> get() 'world' """ def get(): return contents def put(value): nonlocal contents contents = value

42 A Mutable Container def container(contents): """Return a container that is manipulated by two functions. >>> get, put = container('hello') >>> get() 'hello' >>> put('world') >>> get() 'world' """ def get(): return contents def put(value): nonlocal contents contents = value return put, get

43 Dispatch Functions

44 Dispatch Functions A technique for packing multiple behaviors into one function

45 Dispatch Functions A technique for packing multiple behaviors into one function def pair(x, y): """Return a function that behaves like a pair.""" def dispatch(m): if m == 0: return x elif m == 1: return y return dispatch

46 Dispatch Functions A technique for packing multiple behaviors into one function def pair(x, y): """Return a function that behaves like a pair.""" def dispatch(m): if m == 0: return x elif m == 1: return y return dispatch Message argument can be anything, but strings are most common

47 Dispatch Functions A technique for packing multiple behaviors into one function def pair(x, y): """Return a function that behaves like a pair.""" def dispatch(m): if m == 0: return x elif m == 1: return y return dispatch Message argument can be anything, but strings are most common The body of a dispatch function is always the same: st common

48 Dispatch Functions A technique for packing multiple behaviors into one function def pair(x, y): """Return a function that behaves like a pair.""" def dispatch(m): if m == 0: return x elif m == 1: return y return dispatch Message argument can be anything, but strings are most common The body of a dispatch function is always the same: One conditional statement with several clauses

49 Dispatch Functions A technique for packing multiple behaviors into one function def pair(x, y): """Return a function that behaves like a pair.""" def dispatch(m): if m == 0: return x elif m == 1: return y return dispatch Message argument can be anything, but strings are most common The body of a dispatch function is always the same: One conditional statement with several clauses Headers perform equality tests on the message

50 Message Passing

51 Message Passing An approach to organizing the relationship among different pieces of a program

52 Message Passing An approach to organizing the relationship among different pieces of a program Different objects pass messages to each other

53 Message Passing An approach to organizing the relationship among different pieces of a program Different objects pass messages to each other What is your fourth element?

54 Message Passing An approach to organizing the relationship among different pieces of a program Different objects pass messages to each other What is your fourth element? Change your third element to this new value. (please?)

55 Message Passing An approach to organizing the relationship among different pieces of a program Different objects pass messages to each other What is your fourth element? Change your third element to this new value. (please?) Encapsulates the behavior of all operations on a piece of data

56 Message Passing An approach to organizing the relationship among different pieces of a program Different objects pass messages to each other What is your fourth element? Change your third element to this new value. (please?) Encapsulates the behavior of all operations on a piece of data Important historical role: The message passing approach strongly influenced object oriented programming (next lecture)

57 Mutable Container with Message Passing def container(contents): def get(): return contents def put(value): nonlocal contents contents = value return put, get

58 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def get(): return contents def put(value): nonlocal contents contents = value return put, get

59 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def dispatch(message, value=none): def get(): return contents def put(value): nonlocal contents contents = value return put, get

60 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def dispatch(message, value=none): nonlocal contents def get(): return contents def put(value): nonlocal contents contents = value return put, get

61 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def dispatch(message, value=none): nonlocal contents if message == 'get': def get(): return contents def put(value): nonlocal contents contents = value return put, get

62 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def dispatch(message, value=none): nonlocal contents if message == 'get': return contents def get(): return contents def put(value): nonlocal contents contents = value return put, get

63 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def dispatch(message, value=none): nonlocal contents if message == 'get': return contents if message == put': def get(): return contents def put(value): nonlocal contents contents = value return put, get

64 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def dispatch(message, value=none): nonlocal contents if message == 'get': return contents if message == put': contents = value def get(): return contents def put(value): nonlocal contents contents = value return put, get

65 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def dispatch(message, value=none): nonlocal contents if message == 'get': return contents if message == put': contents = value def get(): return contents def put(value): nonlocal contents contents = value return dispatch return put, get

66 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def dispatch(message, value=none): nonlocal contents if message == 'get': return contents if message == put': contents = value def get(): return contents def put(value): nonlocal contents contents = value return dispatch return put, get

67 Mutable Container with Message Passing def container_dispatch(contents): def container(contents): def dispatch(message, value=none): nonlocal contents if message == 'get': return contents if message == put': contents = value def get(): return contents def put(value): nonlocal contents contents = value return dispatch return put, get

68 Mutable Recursive Lists

69 Mutable Recursive Lists def mutable_rlist():

70 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist

71 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none):

72 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents

73 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len':

74 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents)

75 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem':

76 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value)

77 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value) elif message == 'push':

78 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value) elif message == 'push': contents = make_rlist(value, contents)

79 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value) elif message == 'push': contents = make_rlist(value, contents) elif message == 'pop':

80 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value) elif message == 'push': contents = make_rlist(value, contents) elif message == 'pop': item = first(contents)

81 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value) elif message == 'push': contents = make_rlist(value, contents) elif message == 'pop': item = first(contents) contents = rest(contents)

82 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value) elif message == 'push': contents = make_rlist(value, contents) elif message == 'pop': item = first(contents) contents = rest(contents) return item

83 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value) elif message == 'push': contents = make_rlist(value, contents) elif message == 'pop': item = first(contents) contents = rest(contents) return item elif message == 'str':

84 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value) elif message == 'push': contents = make_rlist(value, contents) elif message == 'pop': item = first(contents) contents = rest(contents) return item elif message == 'str': return str_rlist(contents)

85 Mutable Recursive Lists def mutable_rlist(): contents = empty_rlist def dispatch(message, value=none): nonlocal contents if message == 'len': return len_rlist(contents) elif message == 'getitem': return getitem_rlist(contents, value) elif message == 'push': contents = make_rlist(value, contents) elif message == 'pop': item = first(contents) contents = rest(contents) return item elif message == 'str': return str_rlist(contents) return dispatch

61A LECTURE 10 MUTABLE DATA. Steven Tang and Eric Tzeng July 10, 2013

61A LECTURE 10 MUTABLE DATA. Steven Tang and Eric Tzeng July 10, 2013 61A LECTURE 10 MUTABLE DATA Steven Tang and Eric Tzeng July 10, 2013 Announcements Do the homework! Keep on studying for Midterm 1! A Function with Evolving Behavior Let's model a bank account that has

More information

CS61A Lecture 16. Amir Kamil UC Berkeley February 27, 2013

CS61A Lecture 16. Amir Kamil UC Berkeley February 27, 2013 CS61A Lecture 16 Amir Kamil UC Berkeley February 27, 2013 Announcements HW5 due tonight Trends project due on Tuesday Partners are required; find one in lab or on Piazza Will not work in IDLE New bug submission

More information

CS61A Lecture 15. Amir Kamil UC Berkeley February 25, 2013

CS61A Lecture 15. Amir Kamil UC Berkeley February 25, 2013 CS61A Lecture 15 Amir Kamil UC Berkeley February 25, 2013 Announcements HW5 due on Wednesday Trends project out Partners are required; find one in lab or on Piazza Will not work in IDLE New bug submission

More information

CS61A Lecture 16. Amir Kamil UC Berkeley February 27, 2013

CS61A Lecture 16. Amir Kamil UC Berkeley February 27, 2013 CS61A Lecture 16 Amir Kamil UC Berkeley February 27, 2013 Announcements HW5 due tonight Trends project due on Tuesday Partners are required; find one in lab or on Piazza Will not work in IDLE New bug submission

More information

61A Lecture 13. Wednesday, September 28

61A Lecture 13. Wednesday, September 28 61A Lecture 13 Wednesday, September 28 Dictionaries {'Dem': 0} 2 Limitations on Dictionaries Dictionaries are unordered collections of key-value pairs. Dictionaries do have two restrictions: A key of a

More information

61A LECTURE 8 SEQUENCES, ITERABLES

61A LECTURE 8 SEQUENCES, ITERABLES 61A LECTURE 8 SEQUENCES, ITERABLES Steven Tang and Eric Tzeng July 8, 013 Announcements Homework 4 due tonight Homework 5 is out, due Friday Midterm is Thursday, 7pm Thanks for coming to the potluck! What

More information

61A LECTURE 8 SEQUENCES, ITERABLES. Steven Tang and Eric Tzeng July 8, 2013

61A LECTURE 8 SEQUENCES, ITERABLES. Steven Tang and Eric Tzeng July 8, 2013 61A LECTURE 8 SEQUENCES, ITERABLES Steven Tang and Eric Tzeng July 8, 2013 Announcements Homework 4 due tonight Homework 5 is out, due Friday Midterm is Thursday, 7pm Thanks for coming to the potluck!

More information

Lecture #12: Immutable and Mutable Data. Last modified: Mon Feb 22 16:33: CS61A: Lecture #12 1

Lecture #12: Immutable and Mutable Data. Last modified: Mon Feb 22 16:33: CS61A: Lecture #12 1 Lecture #12: Immutable and Mutable Data Last modified: Mon Feb 22 16:33:22 2016 CS61A: Lecture #12 1 Listing Leaves def leaf_labels(tree): """A list of the labels of all leaves in TREE.""" Last modified:

More information

CS61A Lecture 21. Amir Kamil UC Berkeley March 11, 2013

CS61A Lecture 21. Amir Kamil UC Berkeley March 11, 2013 CS61A Lecture 21 Amir Kamil UC Berkeley March 11, 2013 Announcements HW7 due on Wednesday Ants project out Looking Up Names Name expressions look up names in the environment Dot expressions look

More information

Lecture #11: Immutable and Mutable Data. Last modified: Sun Feb 19 17:03: CS61A: Lecture #11 1

Lecture #11: Immutable and Mutable Data. Last modified: Sun Feb 19 17:03: CS61A: Lecture #11 1 Lecture #11: Immutable and Mutable Data Last modified: Sun Feb 19 17:03:49 2017 CS61A: Lecture #11 1 Building Recursive Structures In Lecture #9, we defined map rlist and filter rlist: def map rlist(f,

More information

RLISTS AND THE ENVIRONMENT MODEL 9

RLISTS AND THE ENVIRONMENT MODEL 9 RLISTS AND THE ENVIRONMENT MODEL 9 COMPUTER SCIENCE 61A July 17, 2012 1 Recursive Lists (RLists) Earlier in the course, we worked with the Immutable Recursive List (IRList), which is an abstract data type

More information

Structure and Interpretation of Computer Programs Fall 2012 Alternate Midterm 1

Structure and Interpretation of Computer Programs Fall 2012 Alternate Midterm 1 CS 6A Structure and Interpretation of Computer Programs Fall 0 Alternate Midterm INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

More information

Lecture #12: Mutable Data. map rlist Illustrated (III) map rlist Illustrated. Using Mutability For Construction: map rlist Revisited

Lecture #12: Mutable Data. map rlist Illustrated (III) map rlist Illustrated. Using Mutability For Construction: map rlist Revisited Lecture #12: Mutable Data Using Mutability For Construction: map rlist Revisited Even if we never change a data structure once it is constructed, mutation may be useful during its construction. Example:

More information

CS61A Lecture 42. Amir Kamil UC Berkeley April 29, 2013

CS61A Lecture 42. Amir Kamil UC Berkeley April 29, 2013 CS61A Lecture 42 Amir Kamil UC Berkeley April 29, 2013 Announcements HW13 due Wednesday Scheme project due tonight!!! Scheme contest deadline extended to Friday MapReduce Execution Model http://research.google.com/archive/mapreduce

More information

61A LECTURE 7 DATA ABSTRACTION. Steven Tang and Eric Tzeng July 3, 2013

61A LECTURE 7 DATA ABSTRACTION. Steven Tang and Eric Tzeng July 3, 2013 61A LECTURE 7 DATA ABSTRACTION Steven Tang and Eric Tzeng July 3, 2013 Announcements Trends project released later today. Due in ~2 weeks Extra midterm office hours Sunday, from noon to 6pm in 310 Soda

More information

CS61A Lecture 20 Object Oriented Programming: Implementation. Jom Magrotker UC Berkeley EECS July 23, 2012

CS61A Lecture 20 Object Oriented Programming: Implementation. Jom Magrotker UC Berkeley EECS July 23, 2012 CS61A Lecture 20 Object Oriented Programming: Implementation Jom Magrotker UC Berkeley EECS July 23, 2012 COMPUTER SCIENCE IN THE NEWS http://www.theengineer.co.uk/sectors/electronics/news/researchers

More information

Lecture #10: Sequences. Last modified: Mon Feb 22 16:33: CS61A: Lecture #10 1

Lecture #10: Sequences. Last modified: Mon Feb 22 16:33: CS61A: Lecture #10 1 Lecture #10: Sequences Last modified: Mon Feb 22 16:33:26 2016 CS61A: Lecture #10 1 Public Service Announcement Align is a new student organization on campus that hopes to unite undergraduate students

More information

Lecture #3: Environments

Lecture #3: Environments Lecture #3: Environments Substitution is not as simple as it might seem. For example: def f(x): def g(x): return x + 10 return g(5) f(3) When we call f(3), we should not substitute 3 for the xs in g! And

More information

Lecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1

Lecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1 Lecture #15: Generic Functions and Expressivity Last modified: Wed Mar 1 15:51:48 2017 CS61A: Lecture #16 1 Consider the function find: Generic Programming def find(l, x, k): """Return the index in L of

More information

Lecture #12: Mutable Data. Last modified: Sun Feb 19 17:15: CS61A: Lecture #12 1

Lecture #12: Mutable Data. Last modified: Sun Feb 19 17:15: CS61A: Lecture #12 1 Lecture #12: Mutable Data Last modified: Sun Feb 19 17:15:18 2017 CS61A: Lecture #12 1 Using Mutability For Construction: map rlist Revisited Even if we never change a data structure once it is constructed,

More information

Before we can talk about concurrency, we need to first understand what happens under the hood when the interpreter executes a Python statement.

Before we can talk about concurrency, we need to first understand what happens under the hood when the interpreter executes a Python statement. CS61A Notes Week 14 Concurrency Notes adapted from Justin Chen, Chung Wu, and George Wang On your computer, you often have multiple programs running at the same time. You might have your internet browser

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 6A Spring 203 Structure and Interpretation of Computer Programs Final Solutions INSTRUCTIONS You have 3 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

More information

ENVIRONMENT MODEL: FUNCTIONS, DATA 18

ENVIRONMENT MODEL: FUNCTIONS, DATA 18 ENVIRONMENT MODEL: FUNCTIONS, DATA 18 COMPUTER SCIENCE 61A Jon Kotker and Tom Magrino July 18, 2012 1 Motivation Yesterday, we introduced the environment model of computation as an alternative to the earlier

More information

Stateful Objects. can I withdraw 100 CHF? may vary over the course of the lifetime of the account.

Stateful Objects. can I withdraw 100 CHF? may vary over the course of the lifetime of the account. Functions and State Functions and State Until now, our programs have been side-effect free. Therefore, the concept of time wasn t important. For all programs that terminate, any sequence of actions would

More information

Object-Oriented Programming

Object-Oriented Programming 61A Lecture 15 Announcements Object-Oriented Programming Object-Oriented Programming A method for organizing programs Data abstraction Bundling together information and related behavior John's Account

More information

DATA ABSTRACTION 5. February 21, 2013

DATA ABSTRACTION 5. February 21, 2013 DATA ABSTRACTION 5 COMPUTER SCIENCE 61A February 21, 2013 1 Data Abstraction Data abstraction is a powerful concept in computer science that allows programmers to treat code as objects for example, car

More information

Programming Paradigms in Python

Programming Paradigms in Python Programming Paradigms in Python Johan Falkenjack February 5, 2018 Programming Paradigms An overarching philosophy about programming Execution model Code organization Most famous paradigms: Imperative (write

More information

61A Lecture 3. Friday, September 5

61A Lecture 3. Friday, September 5 61A Lecture 3 Friday, September 5 Announcements There's plenty of room in live lecture if you want to come (but videos are still better) Please don't make noise outside of the previous lecture! Homework

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation Outline Problem: Create, read in and print out four sets of student grades Setting up the problem Breaking

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques () Lecture 13 February 12, 2018 Mutable State & Abstract Stack Machine Chapters 14 &15 Homework 4 Announcements due on February 20. Out this morning Midterm results

More information

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013 61A LECTURE 1 FUNCTIONS, VALUES Steven Tang and Eric Tzeng June 24, 2013 Welcome to CS61A! The Course Staff - Lecturers Steven Tang Graduated L&S CS from Cal Back for a PhD in Education Eric Tzeng Graduated

More information

CS61B Lecture #7. Announcements:

CS61B Lecture #7. Announcements: Announcements: CS61B Lecture #7 New discussion section: Tuesday 2 3PM in 310 Soda. New lab section: Thursday 2 4PM in 273 Soda. Programming Contest coming up: 5 October (new date). Watch for details. Last

More information

CS61A Lecture 32. Amir Kamil UC Berkeley April 5, 2013

CS61A Lecture 32. Amir Kamil UC Berkeley April 5, 2013 CS61A Lecture 32 Amir Kamil UC Berkeley April 5, 2013 Announcements Hog revisions due Monday HW10 due Wednesday Make sure to fill out survey on Piazza We need to schedule alternate final exam times for

More information

COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 21 Scheme TODAY REVIEW: DISPATCH DICTIONARIES DISPATCH DICTIONARIES 7/27/2012

COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 21 Scheme TODAY REVIEW: DISPATCH DICTIONARIES DISPATCH DICTIONARIES 7/27/2012 COMPUTER SCIENCE IN THE NEWS CS6A Lecture 2 Scheme Jom Magrotker UC Berkeley EECS July 24, 202 http://spectrum.ieee.org/tech talk/robotics/artificial intelligence/a texas hold em tournament for ais 2 TODAY

More information

CS61A Lecture 1. Amir Kamil UC Berkeley January 23, 2013

CS61A Lecture 1. Amir Kamil UC Berkeley January 23, 2013 CS61A Lecture 1 Amir Kamil UC Berkeley January 23, 2013 Welcome to CS61A! The Course Staff I ve been at Berkeley a long time, and took CS61A a while back. Read the course info to find out when! TAs essentially

More information

Announcements. Homework 1 due Monday 10/12 (today) Homework 2 released next Monday 10/19 is due 11/2

Announcements. Homework 1 due Monday 10/12 (today) Homework 2 released next Monday 10/19 is due 11/2 61A Extra Lecture 6 Announcements Homework 1 due Monday 10/12 (today) Homework 2 released next Monday 10/19 is due 11/2 Homework 3 is to complete an extension to Project 4 Due at the same time as Project

More information

Computational Concepts Toolbox. Object Oriented Programming. Today: class. Review: Objects

Computational Concepts Toolbox. Object Oriented Programming. Today: class. Review: Objects Computational Concepts Toolbox Object Oriented Programming David E Culler CS8 Computational Structures in Data Science http://insteecsberkeleyedu/~cs88 Lecture 8 March 28, 2016 Data type: values, literals,

More information

Header Description: This use case describes how the ATM user withdraws cash from the ATM.

Header Description: This use case describes how the ATM user withdraws cash from the ATM. Use Case: Withdraw Cash Use Case #: UC1 Author: Iteration: JAD Team Detailed Header Description: This use case describes how the ATM user withdraws cash from the ATM. Business Trigger(s): Customer needs

More information

MEMOIZATION, RECURSIVE DATA, AND SETS

MEMOIZATION, RECURSIVE DATA, AND SETS MEMOIZATION, RECURSIVE DATA, AND SETS 4b COMPUTER SCIENCE 61A July 18, 2013 1 Memoization Later in this class, you ll learn about orders of growth and how to analyze exactly how efficient (or inefficient)

More information

CS61A Lecture 36. Soumya Basu UC Berkeley April 15, 2013

CS61A Lecture 36. Soumya Basu UC Berkeley April 15, 2013 CS61A Lecture 36 Soumya Basu UC Berkeley April 15, 2013 Announcements HW11 due Wednesday Scheme project, contest out Our Sequence Abstraction Recall our previous sequence interface: A sequence has a finite,

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming David E. Culler CS8 Computational Structures in Data Science http://inst.eecs.berkeley.edu/~cs88 Lecture 8 March 28, 2016 Computational Concepts Toolbox Data type: values, literals,

More information

Fundamentals of Programming (Python) Object-Oriented Programming. Ali Taheri Sharif University of Technology Spring 2018

Fundamentals of Programming (Python) Object-Oriented Programming. Ali Taheri Sharif University of Technology Spring 2018 Fundamentals of Programming (Python) Object-Oriented Programming Ali Taheri Sharif University of Technology Outline 1. Python Data Types 2. Classes and Objects 3. Defining Classes 4. Working with Objects

More information

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

CSC 148 Lecture 3. Dynamic Typing, Scoping, and Namespaces. Recursion CSC 148 Lecture 3 Dynamic Typing, Scoping, and Namespaces Recursion Announcements Python Ramp Up Session Monday June 1st, 1 5pm. BA3195 This will be a more detailed introduction to the Python language

More information

Chapter 2: Building Abstractions with Objects

Chapter 2: Building Abstractions with Objects Chapter 2: Building Abstractions with Objects Contents 2.1 Introduction 1 2.1.1 The Object Metaphor........................................ 1 2.1.2 Native Data Types..........................................

More information

CSE : Python Programming

CSE : Python Programming CSE 399-004: Python Programming Lecture 10: Functional programming, Memoization March 26, 2007 http://www.seas.upenn.edu/~cse39904/ Announcements Should have received email about meeting times Length:

More information

Week 8: Functions and States

Week 8: Functions and States Week 8: Functions and States Until now, our programs have been side-eect free. Therefore, the concept of time wasn't important. For all programs that terminate, any sequence of actions would have given

More information

PREPARING FOR PRELIM 1

PREPARING FOR PRELIM 1 PREPARING FOR PRELIM 1 CS 1110: FALL 2012 This handout explains what you have to know for the first prelim. There will be a review session with detailed examples to help you study. To prepare for the prelim,

More information

Anatomy of a Method. HW3 is due Today. September 15, Midterm 1. Quick review of last lecture. Encapsulation. Encapsulation

Anatomy of a Method. HW3 is due Today. September 15, Midterm 1. Quick review of last lecture. Encapsulation. Encapsulation Anatomy of a Method September 15, 2006 HW3 is due Today ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev Midterm 1 Next Tuesday Sep 19 @ 6:30 7:45pm. Location:

More information

1 State, objects, and abstraction

1 State, objects, and abstraction 6.01, Spring Semester, 2008 Course notes for Week 4 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.01 Introduction to EECS I Spring Semester, 2008 Course

More information

CONCURRENCY AND MAPREDUCE 15

CONCURRENCY AND MAPREDUCE 15 CONCURRENCY AND MAPREDUCE 15 COMPUTER SCIENCE 61A August 3, 2014 1 Concurrency On your computer, you often use multiple programs at the same time. You might be reading Piazza posts on your internet browser,

More information

Streams and Evalutation Strategies

Streams and Evalutation Strategies Data and Program Structure Streams and Evalutation Strategies Lecture V Ahmed Rezine Linköpings Universitet TDDA69, VT 2014 Lecture 2: Class descriptions - message passing ( define ( make-account balance

More information

Announcements. Last modified: Fri Sep 8 00:59: CS61B: Lecture #7 1

Announcements. Last modified: Fri Sep 8 00:59: CS61B: Lecture #7 1 Announcements Sign-ups for weekly group tutoring offered by the course tutors have been released! Form will close on Saturday, 9/9, at 11:59PM. You will receive room and time assignments on Sunday via

More information

61A Lecture 2. Wednesday, September 4, 2013

61A Lecture 2. Wednesday, September 4, 2013 61A Lecture 2 Wednesday, September 4, 2013 Names, Assignment, and User-Defined Functions (Demo) Types of Expressions Primitive expressions: 2 add 'hello' Number or Numeral Name String Call expressions:

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

Lecture #7: Recursion (and a data structure)

Lecture #7: Recursion (and a data structure) Lecture #7: Recursion (and a data structure) Announcements: A message from the AWE: The Association of Women in EECS is hosting a 61A party this Sunday (2/9) from 1 3PM in the Woz! Come hang out, befriend

More information

ENGR 102 Engineering Lab I - Computation

ENGR 102 Engineering Lab I - Computation ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;

More information

Lecture 19. Operators and Abstraction

Lecture 19. Operators and Abstraction Lecture 19 Operators and Abstraction Announcements Reading Tuesday: Chapter 18 Thursday reading online Assignments A4 due tonight at Midnight 10 pts per day late Consultants available tonight A5 posted

More information

Lecture #16: Generic Functions and Expressivity. Last modified: Fri Feb 26 19:16: CS61A: Lecture #16 1

Lecture #16: Generic Functions and Expressivity. Last modified: Fri Feb 26 19:16: CS61A: Lecture #16 1 Lecture #16: Generic Functions and Expressivity Last modified: Fri Feb 26 19:16:38 2016 CS61A: Lecture #16 1 Consider the function find: Generic Programming def find(l, x, k): """Return the index in L

More information

User Defined Types. Babes-Bolyai University Lecture 06. Lect Phd. Arthur Molnar. User defined types. Python scope and namespace

User Defined Types. Babes-Bolyai University Lecture 06. Lect Phd. Arthur Molnar. User defined types. Python scope and namespace ? User Defined Types Babes-Bolyai University arthur@cs.ubbcluj.ro Overview? 1? 2 3 ? NB! Types classify values. A type denotes a domain (a set of values) operations on those values. ? Object oriented programming

More information

STRUCTURE AND INTERPRETATION COMPUTER PROGRAMS >>> COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 23 Py TODAY REVIEW: INTERPRETATION 7/26/2012 READ PRINT

STRUCTURE AND INTERPRETATION COMPUTER PROGRAMS >>> COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 23 Py TODAY REVIEW: INTERPRETATION 7/26/2012 READ PRINT COMPUTER SCIENCE IN THE NEWS CS61A Lecture 23 Py Jom Magrotker UC Berkeley EECS July 26, 2012 http://www.theverge.com/2012/7/26/3188043/robot-baby-osaka-university-asada-laboratory 2 TODAY Interpretation:

More information

61A Lecture 19. Wednesday, October 12

61A Lecture 19. Wednesday, October 12 61A Lecture 19 Wednesday, October 12 What Are Programs? Once upon a time, people wrote programs on blackboards Every once in a while, they would "punch in" a program Now, we type programs as text files

More information

STRUCTURE AND INTERPRETATION COMPUTER PROGRAMS COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 23 Py TODAY 7/26/2012

STRUCTURE AND INTERPRETATION COMPUTER PROGRAMS COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 23 Py TODAY 7/26/2012 COMPUTER SCIENCE IN THE NEWS CS61A Lecture 23 Py Jom Magrotker UC Berkeley EECS July 26, 2012 http://www.theverge.com/2012/7/26/3188043/robot-baby-osaka-university-asada-laboratory 2 TODAY Interpretation:

More information

CS 360 Programming Languages Day 14 Closure Idioms

CS 360 Programming Languages Day 14 Closure Idioms CS 360 Programming Languages Day 14 Closure Idioms Why lexical scope rocks Last time: currying Today: implementing callbacks and object-oriented programming. Review: mutable state Racket's variables are

More information

CS61A Lecture 15 Object Oriented Programming, Mutable Data Structures. Jom Magrotker UC Berkeley EECS July 12, 2012

CS61A Lecture 15 Object Oriented Programming, Mutable Data Structures. Jom Magrotker UC Berkeley EECS July 12, 2012 CS61A Lecture 15 Object Oriented Programming, Mutable Data Structures Jom Magrotker UC Berkeley EECS July 12, 2012 COMPUTER SCIENCE IN THE NEWS http://www.iospress.nl/ios_news/music to my eyes device converting

More information

Chapter 4: Distributed and Parallel Computing

Chapter 4: Distributed and Parallel Computing Chapter 4: Distributed and Parallel Computing Contents 4.1 Introduction 1 4.2 Distributed Computing 1 4.2.1 Client/Server Systems........................................ 1 4.2.2 Peer-to-peer Systems........................................

More information

Constraint Programming. Thursday, February 26

Constraint Programming. Thursday, February 26 Constraint Programming Thursday, February 26 Motivation 9 * celsius = 5 * (fahrenheit - 32) Given celsius, how do you find fahrenheit? Given fahrenheit, how do you find celsius? Motivation 9 * celsius

More information

! The simplest building blocks of a language. ! Compound elements are built from simpler ones

! The simplest building blocks of a language. ! Compound elements are built from simpler ones The Elements of Programming Primitive Expressions and Statements! The simplest building blocks of a language 61 Lecture Monday, ugust 9 Means of Combination! Compound elements are built from simpler ones

More information

CS Prelim 2 Review Fall 2018

CS Prelim 2 Review Fall 2018 CS 1110 Prelim 2 Review Fall 2018 Exam Info Prelim 1: Thursday, November 8th Last name L P at 5:15 6:45 in Uris G01 Last name Q Z at 5:15 6:45 in Statler Aud. Last name A D at 7:30 9:00 in Uris G01 Last

More information

CS61A Lecture 23 Py. Jom Magrotker UC Berkeley EECS July 26, 2012

CS61A Lecture 23 Py. Jom Magrotker UC Berkeley EECS July 26, 2012 CS61A Lecture 23 Py Jom Magrotker UC Berkeley EECS July 26, 2012 COMPUTERSCIENCE IN THENEWS http://www.theverge.com/2012/7/26/3188043/robot-baby-osaka-university-asada-laboratory 2 TODAY Interpretation:

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 61A Fall 2013 Structure and Interpretation of Computer Programs Final Solutions INSTRUCTIONS You have 3 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

More information

CS61A Lecture 9 Immutable Data Structures. Jom Magrotker UC Berkeley EECS July 2, 2012

CS61A Lecture 9 Immutable Data Structures. Jom Magrotker UC Berkeley EECS July 2, 2012 CS61A Lecture 9 Immutable Data Structures Jom Magrotker UC Berkeley EECS July 2, 2012 COMPUTER SCIENCE IN THE NEWS Google unveils Glass at Google I/O, June 27 Prototypes available to developers at the

More information

Lecture 5. Defining Functions

Lecture 5. Defining Functions Lecture 5 Defining Functions Announcements for this Lecture Last Call Quiz: About the Course Take it by tomorrow Also remember the survey Readings Sections 3.5 3.3 today Also 6.-6.4 See online readings

More information

Iterators & Generators

Iterators & Generators Iterators & Generators Sequences A sequence is something that you can: Index into Get the length of What are some examples of sequences? Sequences We ve been working with sequences all semester! Examples:

More information

Chapter 2: Building Abstractions with Data

Chapter 2: Building Abstractions with Data Chapter 2: Building Abstractions with Data Contents 2.1 Introduction 1 2.2 Data Abstraction 1 2.2.1 Example: Arithmetic on Rational Numbers............................. 2 2.2.2 Tuples................................................

More information

Python in 10 (50) minutes

Python in 10 (50) minutes Python in 10 (50) minutes https://www.stavros.io/tutorials/python/ Python for Microcontrollers Getting started with MicroPython Donald Norris, McGrawHill (2017) Python is strongly typed (i.e. types are

More information

2.2 Data Abstraction

2.2 Data Abstraction ITP 20005 Programming Languages Chapter 2 Building Abstractions with Data 2.1 Introduction Functional Abstraction vs. Data Abstraction 2.2 Data Abstraction Example: Rational Numbers Major references: 1.

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 26 March 23, 2016 Inheritance and Dynamic Dispatch Chapter 24 Inheritance Example public class { private int x; public () { x = 0; } public void incby(int

More information

EXCEPTIONS, CALCULATOR 10

EXCEPTIONS, CALCULATOR 10 EXCEPTIONS, CALCULATOR 10 COMPUTER SCIENCE 61A November 5th, 2012 We are beginning to dive into the realm of interpreting computer programs - that is, writing programs that understand programs. In order

More information

ECE 364 Software Engineering Tools Laboratory. Lecture 7 Python: Object Oriented Programming

ECE 364 Software Engineering Tools Laboratory. Lecture 7 Python: Object Oriented Programming ECE 364 Software Engineering Tools Laboratory Lecture 7 Python: Object Oriented Programming 1 Lecture Summary Object Oriented Programming Concepts Object Oriented Programming in Python 2 Object Oriented

More information

3. Functional Programming. Oscar Nierstrasz

3. Functional Programming. Oscar Nierstrasz 3. Functional Programming Oscar Nierstrasz Roadmap > Functional vs. Imperative Programming > Pattern Matching > Referential Transparency > Lazy Evaluation > Recursion > Higher Order and Curried Functions

More information

Implementing Recursion

Implementing Recursion Implementing Recursion Shriram Krishnamurthi 2003-09-19 We ve seen that there are (at least two, fairly distinct ways of representing environments To implement recursive environments, we need to provide

More information

Programming I. Course 9 Introduction to programming

Programming I. Course 9 Introduction to programming Programming I Course 9 Introduction to programming What we talked about? Modules List Comprehension Generators Recursive Functions Files What we talk today? Object Oriented Programming Classes Objects

More information

Lecture #3: Recursion

Lecture #3: Recursion Computational Structures in Data Science CS88 news Homework will have Challenge problems UC Berkeley EECS Adj. Ass. Prof. Dr. Gerald Friedland Lecture #3: Recursion Project 1 coming soon! Site to know:

More information

Conditionals & Control Flow

Conditionals & Control Flow CS 1110: Introduction to Computing Using Python Lecture 8 Conditionals & Control Flow [Andersen, Gries, Lee, Marschner, Van Loan, White] Announcements: Assignment 1 Due tonight at 11:59pm. Suggested early

More information

COMP 364: Functions II

COMP 364: Functions II COMP 364: Functions II Carlos G. Oliver, Christopher Cameron October 2, 2017 1/29 Outline 1. Recap + Warmup 2. Functions Theory: Positional vs Keyword Arguments 3. Functions practice: Namespaces. 4. Practice

More information

61A Lecture 16. Wednesday, October 5

61A Lecture 16. Wednesday, October 5 61A Lecture 16 Wednesday, October 5 Policy Changes Based on the Survey Homework can now be completed in pairs, if you wish. Every individual should still submit his/her own homework Please write your partner's

More information

CSE341 Autumn 2017, Final Examination December 12, 2017

CSE341 Autumn 2017, Final Examination December 12, 2017 CSE341 Autumn 2017, Final Examination December 12, 2017 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. except for both sides of one 8.5x11in piece of paper. Please

More information

CS1 Lecture 12 Feb. 11, 2019

CS1 Lecture 12 Feb. 11, 2019 CS1 Lecture 12 Feb. 11, 2019 HW4 available tomorrow, due next Wed. Discussion sections this week will be closely tied to one of the homework problems. Exam 1, Thursday evening, 2/21, 6:30-8:00pm HW2 scores

More information

Berkeley Scheme s OOP

Berkeley Scheme s OOP Page < 1 > Berkeley Scheme s OOP Introduction to Mutation If we want to directly change the value of a variable, we need a new special form, set! (pronounced set BANG! ). (set! )

More information

CS251 Programming Languages Handout # 29 Prof. Lyn Turbak March 7, 2007 Wellesley College

CS251 Programming Languages Handout # 29 Prof. Lyn Turbak March 7, 2007 Wellesley College CS5 Programming Languages Handout # 9 Prof. Lyn Turbak March, 00 Wellesley College Postfix: A Simple Stack Language Several exercises and examples in this course will involve the Postfix mini-language.

More information

Lecture #3: Recursion

Lecture #3: Recursion Computational Structures in Data Science UC Berkeley EECS Adj. Ass. Prof. Dr. Gerald Friedland Lecture #3: Recursion Go watch Inception! (Movie about recursion) February 2nd, 2018 http://inst.eecs.berkeley.edu/~cs88

More information

CIS192 Python Programming. Robert Rand. August 27, 2015

CIS192 Python Programming. Robert Rand. August 27, 2015 CIS192 Python Programming Introduction Robert Rand University of Pennsylvania August 27, 2015 Robert Rand (University of Pennsylvania) CIS 192 August 27, 2015 1 / 30 Outline 1 Logistics Grading Office

More information

What s different about Factor?

What s different about Factor? Harshal Lehri What s different about Factor? Factor is a concatenative programming language - A program can be viewed as a series of functions applied on data Factor is a stack oriented program - Data

More information

CS4215 Programming Language Implementation. Martin Henz

CS4215 Programming Language Implementation. Martin Henz CS4215 Programming Language Implementation Martin Henz Thursday 15 March, 2012 2 Chapter 11 impl: A Simple Imperative Language 11.1 Introduction So far, we considered only languages, in which an identifier

More information

Lecture #21: Search Trees, Sets. Last modified: Tue Mar 18 18:15: CS61A: Lecture #21 1

Lecture #21: Search Trees, Sets. Last modified: Tue Mar 18 18:15: CS61A: Lecture #21 1 Lecture #21: Search Trees, Sets Last modified: Tue Mar 18 18:15:49 2014 CS61A: Lecture #21 1 General Tree Class (From Last Lecture) class Tree: """A Tree consists of a label and a sequence of 0 or more

More information

Lecture 7. Memory in Python

Lecture 7. Memory in Python Lecture 7 Memory in Python Announcements For This Lecture Readings Reread Chapter 3 No reading for Thursday Lab Work on Assignment Credit when submit A Nothing else to do Assignment Moved to Fri, Sep.

More information

Python List built-in methods, accessing elements, selection, slicing, recursive functions, list comprehension

Python List built-in methods, accessing elements, selection, slicing, recursive functions, list comprehension ITP 20005 Programming Languages Chapter 2 Building Abstractions with Data 2.1 Introduction 2.2 Data Abstraction 2.3 Sequences List, Tuple, String, Linked List Major references: 1. Structure and Interpretation

More information

t=t + "g"; On the other hand, arrays are mutable. The assignment a[i]=e/// where e element is equal 6

t=t + g; On the other hand, arrays are mutable. The assignment a[i]=e/// where e element is equal 6 Object Oriented Concepts 1.1. Mutability All objects either are immutable or mutable. the state of an immutable object never changes, while the state of a mutable object can change. String object are mutable,

More information

Lists, loops and decisions

Lists, loops and decisions Caltech/LEAD Summer 2012 Computer Science Lecture 4: July 11, 2012 Lists, loops and decisions Lists Today Looping with the for statement Making decisions with the if statement Lists A list is a sequence

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 6A Fall 05 Structure and Interpretation of Computer Programs Final INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator, except

More information