102
61A Lecture 1 Friday, August 24, 2012

61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

61A Lecture 1

Friday, August 24, 2012

Page 2: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Welcome to Berkeley Computer Science!

2

Page 3: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

The Course Staff

3

Page 4: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

The Course Staff

3

Page 5: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

The Course Staff

3

Page 6: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

The Course Staff

3

0 1 2 3 4 5 years

Page 7: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

The Course Staff

3

0 1 2 3 4 5 years

TAs run sections, labs, and also everything else

Page 8: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

The Course Staff

3

0 1 2 3 4 5 years

TAs run sections, labs, and also everything else

Page 9: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

The Course Staff

3

0 1 2 3 4 5 years

TAs run sections, labs, and also everything else

Readers are your personal programming mentors

Page 10: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

The Course Staff

3

0 1 2 3 4 5 years

TAs run sections, labs, and also everything else

Readers are your personal programming mentorsLab Assistants ensure that you don’t get stuck

Page 11: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

4

Page 12: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

4

Page 13: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

4

Page 14: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

4

Page 15: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

Security

4

Page 16: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

Security

Networking

Programming Languages

Theory

Scientific Computing

...

4

Page 17: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

Security

Networking

Programming Languages

Theory

Scientific Computing

...

4

Page 18: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

Security

Networking

Programming Languages

Theory

Scientific Computing

...

4

Computer Vision

Page 19: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

Security

Networking

Programming Languages

Theory

Scientific Computing

...

4

Computer Vision

Planning

Page 20: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

Security

Networking

Programming Languages

Theory

Scientific Computing

...

4

Computer Vision

Planning

Robotics

Page 21: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

Security

Networking

Programming Languages

Theory

Scientific Computing

...

4

Computer Vision

Planning

Robotics

Natural Language Processing

Page 22: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

Security

Networking

Programming Languages

Theory

Scientific Computing

...

4

Computer Vision

Planning

Robotics

Natural Language Processing

...

Page 23: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is Computer Science?

Systems

Artificial Intelligence

Graphics

Security

Networking

Programming Languages

Theory

Scientific Computing

...

4

Computer Vision

Planning

Robotics

Natural Language Processing

...

Page 24: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

5

Page 25: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

• A course about managing complexity

5

Page 26: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

• A course about managing complexity

Mastering abstraction

5

Page 27: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

• A course about managing complexity

Mastering abstraction

Not about 1’s and 0’s

5

Page 28: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

• A course about managing complexity

Mastering abstraction

Not about 1’s and 0’s

• An introduction to Python

5

Page 29: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

• A course about managing complexity

Mastering abstraction

Not about 1’s and 0’s

• An introduction to Python

All the features we really need: introduced today

5

Page 30: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

• A course about managing complexity

Mastering abstraction

Not about 1’s and 0’s

• An introduction to Python

All the features we really need: introduced today

Understanding through implementation

5

Page 31: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

• A course about managing complexity

Mastering abstraction

Not about 1’s and 0’s

• An introduction to Python

All the features we really need: introduced today

Understanding through implementation

Programs that run other programs: meta-evaluation

5

Page 32: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

• A course about managing complexity

Mastering abstraction

Not about 1’s and 0’s

• An introduction to Python

All the features we really need: introduced today

Understanding through implementation

Programs that run other programs: meta-evaluation

• A challenging course that will demand a lot of you

5

Page 33: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

What is 61A?

6

Plone Conference. Photo courtesy of Kriszta Szita

Page 34: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Alternatives to 61A

7

Page 35: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Alternatives to 61A

7

CS 61AS: Self-paced 61A

Page 36: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Alternatives to 61A

7

CS 10: The Beauty and Joy of Computing

CS 61AS: Self-paced 61A

Page 37: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Course Policies

8

Page 38: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Course Policies

8

The purpose of this course is to help you learn

Page 39: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Course Policies

The staff is here to make you successful

8

The purpose of this course is to help you learn

Page 40: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Course Policies

The staff is here to make you successful

8

The purpose of this course is to help you learn

All the details are online:

http://inst.eecs.berkeley.edu/~cs61A/fa12/about.html

Page 41: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Collaboration

9

Page 42: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Collaboration

• Discuss everything with each other

9

Page 43: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Collaboration

• Discuss everything with each other

• EPA: Effort, participation, and altruism

9

Page 44: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Collaboration

• Discuss everything with each other

• EPA: Effort, participation, and altruism• Homework can be completed with a partner

9

Page 45: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Collaboration

• Discuss everything with each other

• EPA: Effort, participation, and altruism• Homework can be completed with a partner

• Projects should be completed with a partner

9

Page 46: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Collaboration

• Discuss everything with each other

• EPA: Effort, participation, and altruism• Homework can be completed with a partner

• Projects should be completed with a partner

• Find a project partner in your section!

9

Page 47: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Collaboration

• Discuss everything with each other

• EPA: Effort, participation, and altruism• Homework can be completed with a partner

• Projects should be completed with a partner

• Find a project partner in your section!

9

The limits of collaboration

Page 48: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Collaboration

• Discuss everything with each other

• EPA: Effort, participation, and altruism• Homework can be completed with a partner

• Projects should be completed with a partner

• Find a project partner in your section!

9

• One simple rule: don’t share code

The limits of collaboration

Page 49: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Collaboration

• Discuss everything with each other

• EPA: Effort, participation, and altruism• Homework can be completed with a partner

• Projects should be completed with a partner

• Find a project partner in your section!

9

• One simple rule: don’t share code

• Copying project solutions is a serious offense!

The limits of collaboration

Page 50: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Announcements

10

Page 51: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Announcements

• Next week, both section and lab will meet in the lab rooms.

10

Page 52: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Announcements

• Next week, both section and lab will meet in the lab rooms.

• Homework 1 is posted! All homework is graded on effort.

10

Page 53: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Announcements

• Next week, both section and lab will meet in the lab rooms.

• Homework 1 is posted! All homework is graded on effort.

• If you are on the waitlist, still complete assignments!

10

Page 54: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Announcements

• Next week, both section and lab will meet in the lab rooms.

• Homework 1 is posted! All homework is graded on effort.

• If you are on the waitlist, still complete assignments!

• Midterms are on 9/19 and 10/24. Final exam is on 12/13.

10

Page 55: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Announcements

• Next week, both section and lab will meet in the lab rooms.

• Homework 1 is posted! All homework is graded on effort.

• If you are on the waitlist, still complete assignments!

• Midterms are on 9/19 and 10/24. Final exam is on 12/13.

• Read the lecture notes before you come to lecture!

10

Page 56: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Announcements

• Next week, both section and lab will meet in the lab rooms.

• Homework 1 is posted! All homework is graded on effort.

• If you are on the waitlist, still complete assignments!

• Midterms are on 9/19 and 10/24. Final exam is on 12/13.

• Read the lecture notes before you come to lecture!

10

Page 57: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 58: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

18 + 69

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 59: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

18 + 696

23

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 60: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

18 + 696

23 p3493161

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 61: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

18 + 696

23 p3493161

sin⇡

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 62: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

18 + 696

23 p3493161

sin⇡

|� 1869|

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 63: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

18 + 696

23 p3493161

sin⇡

100X

i=1

i

|� 1869|

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 64: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

18 + 696

23 p3493161

sin⇡

100X

i=1

i

|� 1869|

✓69

18

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 65: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

18 + 696

23 p3493161

sin⇡

f(x)100X

i=1

i

|� 1869|

✓69

18

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 66: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

18 + 696

23 p3493161

sin⇡

f(x)100X

i=1

i

|� 1869|

✓69

18

Types of expressions

11

An expression

describes a computation

and evaluates to a value

Page 67: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Call Expressions in Python

All expressions can use function call notation

(Demo)

12

Page 68: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Anatomy of a Call Expression

13

Page 69: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Anatomy of a Call Expression

13

add ( 2 , 3 )

Page 70: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Anatomy of a Call Expression

13

add ( 2 , 3 )

Operator

Page 71: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Anatomy of a Call Expression

13

add ( 2 , 3 )

Operator Operand 0 Operand 1

Page 72: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Anatomy of a Call Expression

13

add ( 2 , 3 )

Operator Operand 0 Operand 1

Operators and operands are expressions

Page 73: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Anatomy of a Call Expression

13

add ( 2 , 3 )

Operator Operand 0 Operand 1

Operators and operands are expressions

So they evaluate to values

Page 74: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Anatomy of a Call Expression

13

Evaluation procedure for call expressions:

add ( 2 , 3 )

Operator Operand 0 Operand 1

Operators and operands are expressions

So they evaluate to values

Page 75: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Anatomy of a Call Expression

13

Evaluation procedure for call expressions:

add ( 2 , 3 )

Operator Operand 0 Operand 1

Operators and operands are expressions

1. Evaluate the operator and operand subexpressions

So they evaluate to values

Page 76: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Anatomy of a Call Expression

13

Evaluation procedure for call expressions:

add ( 2 , 3 )

Operator Operand 0 Operand 1

Operators and operands are expressions

1. Evaluate the operator and operand subexpressions

2. Apply the function that is the value of the operator subexpression to the arguments that are the values of the operand subexpression

So they evaluate to values

Page 77: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

Evaluating Nested Expressions

14

Page 78: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

Evaluating Nested Expressions

14

Page 79: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

Evaluating Nested Expressions

14

mul

Page 80: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

mul

Page 81: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

mul

add

Page 82: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

mul

add 2

Page 83: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

mul

add 2mul(4, 6)

Page 84: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

mul

add 2mul(4, 6)

mul 4 6

Page 85: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

mul

add 2mul(4, 6)

mul 4 6

24

Page 86: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

26mul

add 2mul(4, 6)

mul 4 6

24

Page 87: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

26mul

add 2mul(4, 6)

mul 4 6

24

add(3, 5)

Page 88: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

26mul

add 2mul(4, 6)

mul 4 6

24

add(3, 5)

add 3 5

Page 89: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

26mul

add 2mul(4, 6)

mul 4 6

24

add(3, 5)

add 3 5

8

Page 90: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

208mul(add(2, mul(4, 6)), add(3, 5))

add(2, mul(4, 6))

Evaluating Nested Expressions

14

26mul

add 2mul(4, 6)

mul 4 6

24

add(3, 5)

add 3 5

8

Page 91: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

15

Page 92: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

Page 93: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2

Page 94: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2“The Art of Computer Programming”

Page 95: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2“The Art of Computer Programming”

Donald Knuth

Page 96: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2“The Art of Computer Programming”

Donald KnuthShakespeare’s 37 plays

Page 97: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2“The Art of Computer Programming”

Donald KnuthShakespeare’s 37 plays

Functions: Rules for manipulating data

Page 98: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2“The Art of Computer Programming”

Donald KnuthShakespeare’s 37 plays

Functions: Rules for manipulating data

Add up numbers

Page 99: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2“The Art of Computer Programming”

Donald KnuthShakespeare’s 37 plays

Functions: Rules for manipulating data

Add up numbers

Count the words in a line of text

Page 100: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2“The Art of Computer Programming”

Donald KnuthShakespeare’s 37 plays

Functions: Rules for manipulating data

Add up numbersPronounce someone’s name

Count the words in a line of text

Page 101: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2“The Art of Computer Programming”

Donald KnuthShakespeare’s 37 plays

Functions: Rules for manipulating data

Add up numbersPronounce someone’s name

Count the words in a line of text

(Ka-NOOTH)

Page 102: 61A Lecture 1 - University of California, Berkeleycs61a/fa12/slides/01-Functions_1pp.… · The Course Staff 3 0 1 2 3 4 5 years TAs run sections, labs, and also everything else Readers

Data, Functions, and Interpreters

Data: The things that programs fiddle with

15

2“The Art of Computer Programming”

Donald KnuthShakespeare’s 37 plays

Functions: Rules for manipulating data

Add up numbersPronounce someone’s name

Count the words in a line of text

(Ka-NOOTH)

Interpreter: An implementation of the procedure for evaluation