[公开课] CS61A打卡Spring2018(week1-week8): Structure and Interpretation of Computer Programs
想问的问题:
- HW3: Q2 pingpong: helper function
- HW3: Q7 anonymous factorial
- Disc4:
>>>[[y * 2 for y in [x, x + 1]] for x in [1, 2, 3, 4]]
[[2, 4], [4, 6], [6, 8], [8, 10]]
- Lab5: Q7*
- Disc5:
>>> lst3 = lst2[:]
>>> lst3 is lst2
False
- HW5:Q4
- HW6: Q1
- Lab6: Note: You might run into trouble when you mutate a list as you’re iterating through it. Try iterating through a copy instead! You can use slicing to copy a list:
lst = [2, 2, 2, 2] for element in lst: if element == 2: lst.remove(element) length = len(lst) # length = 2
v.s.lst = [2, 2, 2, 2] for element in lst[:]: if element == 2: lst.remove(element) length = len(lst) #length = 0
Lab6: Q10
2019 Spring: https://cs61a.org
2018 Spring: http://inst.eecs.berkeley.edu/~cs61a/sp18/
计算机程序的构造和解释 (SICP) http://www-mitpress.mit.edu/sicp/full-text/book/book.html
如果想要SICP的书中的练习答案可以到 http://eli.thegreenplace.net/
Lab 2 - 6: 2, 4, 5
Disc 2- 6: 2, 3, 4, 5, 6
HW 2 - 5: 2, 3, 4, 5, 6
Guerrilla 0 - 2: 1(today)
Extra:
Midterm Exam/ Review
Project
-
Project 1: Hog - related videos: 2/23 Lecture 15 Video 1
-
Project 2: Yelp Maps
-
Project 3: Ants Vs. SomeBees
-
Extra 1
-
Extra 2
-
HW 1, 2, 3, 4, 5 (Long)
2/20 -
Spring 2018 Midterm 1 2/8
-
Week 1 (1/15-1/19) : Functions, Names, and Python Basics
-
Week 2 (1/22-1/26) : Control, High-Order Functions, and Environments
-
Week 1&2 : Disc, Lab, HW, Project, Guerrilla
-
Extra 1 (1/24) : Newton Method
-
Week 3 (1/29-2/2) : Iteration, Recursion, Tree Recursion
-
Week 4 (2/5-2/9) : Function Examples, * Midterm 1, Data Abstraction
-
Week 5 (2/12-2/16) : Containers, Trees, Mutable Values
-
Week 6 (2/19-2/23) : Mutable Functions, Objects
-
Week 7 (2/26-3/2) : Inheritance, Representation, Growth
-
Week 8 (3/5-3/9) : Composition, Ordered Sets, Tree Sets
(新的甘特图功能,丰富你的文章)
Mon 07Mon 14Mon 21Mon 28Mon 04Mon 11Mon 18Mon 25Mon 04Mon 11Mon 18Mon 25AprilMon 08Completed task week 1 and week 2 week 1 and week 2 week 1 and week 2 Future task in critical line Create tests for renderer Add to mermaid Total tasksA Gantt Diagram for UCB CS61A- 关于 甘特图 语法,参考 [这儿][2]
CS61A(2018 video with 2019 HW)
-
Week 1 (1/15-1/19) : Functions, Names, and Python Basics
[li] Expressions: (Primitive expressions; Call expressions (Operator and Operand); )
Names, Assignment, and User-Defined Functions;[/li]
- Environment Diagrams;
- Defining Functions: (function signature; function body; Calling User-Defined Functions; Looking Up Names In Environments)
- An environment is a sequence of frames.
- A name evaluates to the value bound to that name - Life Cycle of a User-Defined Function:
- Def statement
- Call expression
- Calling/Applying
Week 2 (1/22-1/26) : Control, High-Order Functions, and Environments
-
[li] Print and None: None Indicates That None Is Returned; Pure Functions & Non-Pure Functions; Nested Expressions with Print;
-
[li]Characteristics of Functions
A function’s domain is the set of all inputs it might possibly take as arguments.
-
Give each function exactly one job.
-
[li]Generalization
Generalizing Patterns with Arguments.
-
Functions defined within other function bodies are bound to names in a local frame.
-
Express general methods of computation
-
[li]Lambda Expressions Versus Def Statements
Both create a function the same domain, range, and behavior.
-
[li]How to Draw Environment Diagram
Week 1&2 : Disc, Lab, HW, Project, Guerrilla
-
HW1: Q4
The function with_if_function uses a call expression, which guarantees that all of its operand subexpressions will be evaluated before if_function is applied to the resulting arguments.
Therefore, even if c returns False, the function t will be called. When we call t, we print out 1. Then, when we call f, we will also print 2.
By contrast, with_if_statement will never call t if c returns False. Thus, we will only call f, printing 2.
>>> n = 3
>>> while n >= 0:
... n -= 1
... print(n)
>>> True and 13
13
>>> False or 0
0
>>> not 10
False
>>> not None
True
>>> True or 1 / 0 or False
True
>>> 0 or False or 2 or 1 / 0
2
>>> (1 + 1) and 1
1
>>> 1/0 or True
Error
Python also includes the boolean operators and, or, and not. These operators are used to combine and manipulate boolean values.
notreturns the opposite truth value of the following expression.
andstops evaluating any more expressions (short-circuits) once it reaches the first false value and returns it. If all values evaluate to a true value, the last value is returned.
orshort-circuits at the first true value and returns it. If all values evaluate to a false value, the last value is returned.
Extra 1 (1/24) : Newton Method
-
[li] Newton Method
UNIX commands
-
Directories:
ls: list the files and folders inside of the current directory
mkdir: make a new directory. For example, mkdir example creates a directory called example
cd: change directories. For example, cd example changes directories to example
rm -r: recursively remove a specified directory. For example, rm -r example removes the example directory and all files and subdirectories inside it.
cat: displays the contents of a file on the screen. For example, cat unix.txt shows the contents of the file unix.txt
mv: moves a file/directory to another file/directory. For example, mv file1 file2 moves the contents of file1 into a (possibly new) file called file2. When moving one file to another, we are effectively renaming the file!
cp: copies a file to another file/directory. For example, cp file1 file2 copies the contents of file1 into a file named file2.
rm: removes a file. For example, rm file1 deletes the file called file1.
echo: displays words on the screen
man: displays manual pages for a specified command
Week 3 (1/29-2/2) : Iteration, Recursion, Tree Recursion
-
[li] Iteration Example: Fibonacci Numbers
-
[li]Iteration is a special case of recursion
-
[li]The Recursive Leap of Faith
- Verify the base case.
- Treat fact as a fucntional abstraction!
- Assume that fact(n-1) is correct.
- VeRify that fact(n) is correct, assuming that fact(n-1) correct.
-
[li]The Luhn Algorithm (credit card)
-
[li]Converting Recursion to Iteration
Can be tricky: Iteration is a special case of recursion.
-
More formulaic: Iteration is a special case of recursion.
-
[li]Order of Recursive Calls
Two Definitions of Cascade: which one is better?
When learning to write recursive functions, put the base cases first.
-
Repetition in Tree-Recursive Computation
-
Recursive decomposition: finding simpler instances of the problem.
-
count_partitions(2, 4)
Extra 2 (1/31) : Decisions
-
[x]
Week 4 (2/5-2/9) : Function Examples, * Midterm 1, Data Abstraction
-
[li] Abstraction
Functional Abstractions
-
Repeated compound expressions
-
[li]Test-Driven Development
Write the test of a function before your write the function.
-
[li]Function Currying: Transforming a multi-argument function into a single-arugment, higher-order function.
-
[li]What Would Python Print?
The print functoin returns None. It also displays its arguments (separated by spaces) when it is called.
-
[li]Rational Numbers Arithmetic Implementation
-
[li]Representing pairs using lists
Week 5 (2/12-2/16) : Containers, Trees, Mutable Values
-
[li] Lists
Working with Lists
The number of elements
len
-
[li]Built-in operators for testing whether an element appears in a compound value
in(looks for individual element in the list, not subsequence)
not in
-
[li]Sequence Unpacking in For Statements
-
[li]The Range Type
Length: ending value - starting value
-
[li]Strings are an abstraction
exec
-
Length and element selection are similar to all sequences
-
[li]Dictionaries are unordered collections of key-value pairs
-
[li]The Closure Property of Data Types
-
[li]Sequence Aggregation
sum(iterable[, start]) -> value
max(a, b, c, …[, key=func]) -> value
-
[li]Tree Abstraction
Recursive description(wooden trees: root label, branches, leaf)
-
[li]Tree Processing Uses Recursion
>>> sum([[1],[2,3],[4]],[])
[1,2,3,4]
>>> sum([ [[1]],[2] ],[])
[[1], 2]
- attributes (bound to value)
- methods: attributes bound to function
-
[li]Objects represent information
-
All objects have attributes
-
[li]Representing Strings: the ASCII Standard
-
[li]Some Objects Can Change (its value over time)
All names that refer ot the same object are affected by a mutation
-
A function can change the value of any object in its scope
-
[li]Tuples are immutable sequences
Immutable values are protected from mutation (cannot change value but binding can be changed)
-
[li]Sameness and Change
<exp0> is <exp1>if
Truethen same
<exp0> == <exp1>if
Truethen equal
Week 6 (2/19-2/23) : Mutable Functions, Objects
-
[li] Mutable Functions
A Function with Behavior That Varies Over Time
- Evaluate all expressions right o f-, from left to right
- Bind the names on the left to the resulting values in the current frame.
nonlocal
-
The Effect of Nonlocal Statements
Effect: Future assignments to that name change its ore-existing binding in the first non-local (Python Docs: an “enclosing scope”) frame of the current environment in which that name is bound.
-
Python pre-computes which frame contains each name before executing the body of a function.
// An highlighted block def make_withdraw(balance): def withdraw(amount): # nonlocal balance if amout > balance: return 'Insufficient funds' balance = balance - amount return balance return withdraw
>>> w = make_withdraw(100)
>>> w(10)
UnboundLocalError: local variable 'balance' referenced before assignment
-
Mutable values (list & dictionary) can be changed without a nonlocal statement.
-
[li]Referential Transparency, Lost
Expressions are referentially transparent if sbustituting an experssion with its value does not change the meaning of a program.
-
[li]OOP:
A method for organizing modular programs
Abstraction barriers
-
Each object has its own local state.
-
[li]The Class Statement:
class <name>: // <suite>A class statement creates a new class and binds that class to <name> in the first frame of the current environment.
-
When a class is called:
- A new instance of that class is created
- The
_init_
method of the class is called with the new object as its first argument (namedself
), along with any additional arguments provided in the call expression. (init is called a constructor, so you can see the relationship between data abstraction and the object-oriented programming with python)
-
Every object that is an instance of a user-defiend class has a unique identity
-
[li]Methods are defined in the suite of a class statement. These def statements create function objects as always, but their names are bound as attributes of the class.
selfparameter, and soh they can all access and manipulate the object’s state.
-
Objects receive messages via dot notation.
getattrand dot expressions look up a name in the same way
-
Python distinguishes between
Functions, which we have been creating since the beginning of the course, and
<expression>.<name>
- Evaluate the <expression> to the left of the dot, which yields the object of the dot expression.
- <name> is matched against the instance attributes of that object; if an attribute with that name exists, its value is returned.
- If not, <name> is looked up in the class, which yields a class attribute value.
- That value is returned unless it is a function, in which case a bound method is returned instead.
-
Class attributes are “shared” across all instances of a class because they are attributes of the class, not the instance.
Week 7 (2/26-3/2) : Inheritance, Representation, Growth
-
[li] Attribute Assignment
Assignment statements with a dot expression on their left-hand side affect attributes for the object of that dot expression.
If the object is an instance, then assignment sets an instance attribute
-
[li]A common uses: Two similar classes differ in their degree of specialization
-
[li]Base class attributes aren’t copied into subclasses
- If it names an attribute in the class, return the attribute value.
- Otherwise, look up the name in the base class, if there is none.
-
[li]Don’t repeat yourself, use existing implementations, try to avoid copying and pasting code.
Attributes that have been overridden are still accessible via class objects.
-
OOP shines when we adopt the metaphor.
-
[li]In python, all objects produce two string representations
The
stris legible to humans
repris legible to the Python interpreter
strand
reprare often the same, but not always.
reprString for an Object
-
The
reprfunction returns a Python expression (a string) that evaluates to an equal object
reprof calling
repron a value is what Python prints in an interactive session
strString for an Object
-
Human interpretable strings are useful as well
stron the value of an expression is what Python prints using the print function.
-
[li]A function that applies to many (poly) different forms (morph) of data
strand
reprare both polymorphic; they apply to any object
reprinvokes a zero-argument method
__repr__on its argument
strinvokes a zero-argument method
__str__on its argument
-
[li]Message passing: Objects interact by looking up attritbues on each other (passing messages)
-
[li]Certain names are special because they have built-in behavior
__init__,
__repr__,
__add__,
__bool__,
__float__refer to python docs
__add__or
__radd__method
-
[li]Idea: Remember the results that have been computed before
-
[li]The Consumption of Space
-
[li]The Consumption of Time
-
[li]Nesting
Week 8 (3/5-3/9) : Composition, Ordered Sets, Tree Sets
-
[li] Linked Lists
Linked List Structure
-
[li]Implementing Sets (assuming they are not built-in)
- [公开课] CS61A打卡Spring2018(week9-week16): Structure and Interpretation of Computer Programs
- 一点SICP(Structure and Interpretation of Computer Programs) 资料 (转载加整理)
- Structure and Interpretation of Computer Programs-Exercise 1.3
- Structure and Interpretation of Computer Programs 读书笔记
- structure and interpretation of computer programs
- 读书笔记(一) -- Structure and interpretation of computer programs
- 【Structure and interpretation of Computer Programs 】学习记录兼导言
- Structure and Interpretation of Computer Programs (the Purple Book)
- [公开课] CS61B打卡(Spring2018) 第二部分week7-14:Data Structures and Algorithms
- 《structs and interpretation of computer program》讀書筆記
- [公开课] CS61B打卡(Spring2018) 第一部分week1-6:Java基础
- 居然还有一本Structure and Interpretation of Classical Mechanics!
- 52.View the Exhibit and examine the structure of the PRODUCTS table.
- 84.View the Exhibit and examine the structure of the EMPLOYEES table.
- springboot tomcat8 duplicate springSecurityFilterChain and increasing the maximum size of the cache
- 131.View the Exhibit and examine the structure of the PRODUCT, COMPONENT, and PDT_COMP tables.
- 132.View the Exhibit and examine the structure of the SALES and PRODUCTS tables.
- Chapter 3 A top-level view of computer function and interconnection
- 《Design of Computer Programs》学习笔记(1 - 4)Winning Poker Hands - Problem Set 1
- 《Design of Computer Programs》学习笔记(1 - 5)Winning Poker Hands - Office Hours 1