61a lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61a lecture 29 monday, november 7 monday,...

104
61A Lecture 29 Monday, November 7 Monday, November 7, 2011

Upload: others

Post on 22-Mar-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

61A Lecture 29

Monday, November 7

Monday, November 7, 2011

Page 2: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Homework: Huffman Encoding Trees

2

Monday, November 7, 2011

Page 3: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Homework: Huffman Encoding Trees

Efficient encoding of strings as ones and zeros (bits).

2

Monday, November 7, 2011

Page 4: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Homework: Huffman Encoding Trees

Efficient encoding of strings as ones and zeros (bits).

2

A 0 C 1010 E 1100 G 1110

B 100 D 1011 F 1101 H 1111

Monday, November 7, 2011

Page 5: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Homework: Huffman Encoding Trees

Efficient encoding of strings as ones and zeros (bits).

2

A 0 C 1010 E 1100 G 1110

B 100 D 1011 F 1101 H 1111

A

B

C D

E F G H

0 1

0 1

0 1

0 1

0 1

0 1 0 1

Monday, November 7, 2011

Page 6: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Decoding a sequence of bits:

Homework: Huffman Encoding Trees

Efficient encoding of strings as ones and zeros (bits).

2

A 0 C 1010 E 1100 G 1110

B 100 D 1011 F 1101 H 1111

A

B

C D

E F G H

0 1

0 1

0 1

0 1

0 1

0 1 0 1

Monday, November 7, 2011

Page 7: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Decoding a sequence of bits:

Homework: Huffman Encoding Trees

Efficient encoding of strings as ones and zeros (bits).

2

A 0 C 1010 E 1100 G 1110

B 100 D 1011 F 1101 H 1111

A

B

C D

E F G H

0 1

0 1

0 1

0 1

0 1

0 1 0 1

1 0 0 0 1 0 1 0

Monday, November 7, 2011

Page 8: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Decoding a sequence of bits:

Homework: Huffman Encoding Trees

Efficient encoding of strings as ones and zeros (bits).

2

A 0 C 1010 E 1100 G 1110

B 100 D 1011 F 1101 H 1111

A

B

C D

E F G H

0 1

0 1

0 1

0 1

0 1

0 1 0 1

1 0 0 0 1 0 1 0

Monday, November 7, 2011

Page 9: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Decoding a sequence of bits:

Homework: Huffman Encoding Trees

Efficient encoding of strings as ones and zeros (bits).

2

A 0 C 1010 E 1100 G 1110

B 100 D 1011 F 1101 H 1111

A

B

C D

E F G H

0 1

0 1

0 1

0 1

0 1

0 1 0 1

1 0 0 0 1 0 1 0

B

Monday, November 7, 2011

Page 10: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Decoding a sequence of bits:

Homework: Huffman Encoding Trees

Efficient encoding of strings as ones and zeros (bits).

2

A 0 C 1010 E 1100 G 1110

B 100 D 1011 F 1101 H 1111

A

B

C D

E F G H

0 1

0 1

0 1

0 1

0 1

0 1 0 1

1 0 0 0 1 0 1 0

B A

Monday, November 7, 2011

Page 11: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Decoding a sequence of bits:

Homework: Huffman Encoding Trees

Efficient encoding of strings as ones and zeros (bits).

2

A 0 C 1010 E 1100 G 1110

B 100 D 1011 F 1101 H 1111

A

B

C D

E F G H

0 1

0 1

0 1

0 1

0 1

0 1 0 1

1 0 0 0 1 0 1 0

B A C

Monday, November 7, 2011

Page 12: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

3

Monday, November 7, 2011

Page 13: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

Data types: Words and sentences (immutable sequences)

3

Monday, November 7, 2011

Page 14: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

Data types: Words and sentences (immutable sequences)

Syntactic forms: Call expressions, literals, and to-statements

3

Monday, November 7, 2011

Page 15: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

Data types: Words and sentences (immutable sequences)

Syntactic forms: Call expressions, literals, and to-statements

3

? print sum 10 difference 7 3

14

Monday, November 7, 2011

Page 16: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

Data types: Words and sentences (immutable sequences)

Syntactic forms: Call expressions, literals, and to-statements

3

? print sum 10 difference 7 3

14

Monday, November 7, 2011

Page 17: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

Data types: Words and sentences (immutable sequences)

Syntactic forms: Call expressions, literals, and to-statements

3

? print sum 10 difference 7 3

14

Monday, November 7, 2011

Page 18: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

Data types: Words and sentences (immutable sequences)

Syntactic forms: Call expressions, literals, and to-statements

3

? print sum 10 difference 7 3

14

Monday, November 7, 2011

Page 19: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

Data types: Words and sentences (immutable sequences)

Syntactic forms: Call expressions, literals, and to-statements

3

? print sum 10 difference 7 3

14

? run [print sum 1 2]

3

Monday, November 7, 2011

Page 20: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

Data types: Words and sentences (immutable sequences)

Syntactic forms: Call expressions, literals, and to-statements

3

? print sum 10 difference 7 3

14

? to double :x

> output sum :x :x

> end

? run [print sum 1 2]

3

Monday, November 7, 2011

Page 21: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Refresher

Data types: Words and sentences (immutable sequences)

Syntactic forms: Call expressions, literals, and to-statements

3

? print sum 10 difference 7 3

14

? to double :x

> output sum :x :x

> end

? print double 4

8

? run [print sum 1 2]

3

Monday, November 7, 2011

Page 22: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

Monday, November 7, 2011

Page 23: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

parser

Monday, November 7, 2011

Page 24: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

parser Evaluator

Monday, November 7, 2011

Page 25: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

parser Evaluator

Monday, November 7, 2011

Page 26: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser Evaluator

Monday, November 7, 2011

Page 27: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser Evaluator

'run [print sum 1 2]'

Monday, November 7, 2011

Page 28: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]'

Monday, November 7, 2011

Page 29: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]

Monday, November 7, 2011

Page 30: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]

Logo words are represented as Python strings

Monday, November 7, 2011

Page 31: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]

Logo words are represented as Python strings

Logo sentences are represented as Python lists

Monday, November 7, 2011

Page 32: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]

Logo words are represented as Python strings

Logo sentences are represented as Python lists

The Parser creates nested sentences, but does not build full expression trees for nested call expressions

Monday, November 7, 2011

Page 33: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]

Logo words are represented as Python strings

Logo sentences are represented as Python lists

The Parser creates nested sentences, but does not build full expression trees for nested call expressions

A line of Logo code

Monday, November 7, 2011

Page 34: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]

Logo words are represented as Python strings

Logo sentences are represented as Python lists

The Parser creates nested sentences, but does not build full expression trees for nested call expressions

A Logo sentence

A line of Logo code

Monday, November 7, 2011

Page 35: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]

Logo words are represented as Python strings

Logo sentences are represented as Python lists

The Parser creates nested sentences, but does not build full expression trees for nested call expressions

A Logo sentence

Another Logo sentence

A line of Logo code

Monday, November 7, 2011

Page 36: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]

Logo words are represented as Python strings

Logo sentences are represented as Python lists

The Parser creates nested sentences, but does not build full expression trees for nested call expressions

A Logo sentence

Another Logo sentence

A line of Logo code

Monday, November 7, 2011

Page 37: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter Architecture

4

string parser line Evaluator

'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]

Logo words are represented as Python strings

Logo sentences are represented as Python lists

The Parser creates nested sentences, but does not build full expression trees for nested call expressions

A Logo sentence

Another Logo sentence

A line of Logo code

Monday, November 7, 2011

Page 38: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

5

Monday, November 7, 2011

Page 39: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

5

Monday, November 7, 2011

Page 40: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

A Buffer instance tracks how much of a line has been used up.

5

Monday, November 7, 2011

Page 41: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

A Buffer instance tracks how much of a line has been used up.

5

>>> buf = Buffer(['show', '2'])

Monday, November 7, 2011

Page 42: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

A Buffer instance tracks how much of a line has been used up.

5

>>> buf = Buffer(['show', '2'])

show 2

Monday, November 7, 2011

Page 43: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

A Buffer instance tracks how much of a line has been used up.

5

>>> buf = Buffer(['show', '2'])

>>> buf.current

'show'

show 2

Monday, November 7, 2011

Page 44: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

A Buffer instance tracks how much of a line has been used up.

5

>>> buf = Buffer(['show', '2'])

>>> buf.current

'show'

>>> print(buf)

[ >> show, 2 ] show 2

Monday, November 7, 2011

Page 45: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

A Buffer instance tracks how much of a line has been used up.

5

>>> buf = Buffer(['show', '2'])

>>> buf.current

'show'

>>> print(buf)

[ >> show, 2 ]

>>> buf.pop()

'show'

show 2

Monday, November 7, 2011

Page 46: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

A Buffer instance tracks how much of a line has been used up.

5

>>> buf = Buffer(['show', '2'])

>>> buf.current

'show'

>>> print(buf)

[ >> show, 2 ]

>>> buf.pop()

'show'

>>> print(buf)

[ show >> 2 ]

show 2

Monday, November 7, 2011

Page 47: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

A Buffer instance tracks how much of a line has been used up.

5

>>> buf = Buffer(['show', '2'])

>>> buf.current

'show'

>>> print(buf)

[ >> show, 2 ]

>>> buf.pop()

'show'

>>> print(buf)

[ show >> 2 ]

>>> buf.pop()

'2'

show 2

Monday, November 7, 2011

Page 48: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Tracking Positions in Lines

A line is used up as it is evaluated

A Buffer instance tracks how much of a line has been used up.

5

>>> buf = Buffer(['show', '2'])

>>> buf.current

'show'

>>> print(buf)

[ >> show, 2 ]

>>> buf.pop()

'show'

>>> print(buf)

[ show >> 2 ]

>>> buf.pop()

'2'

show 2

Demo

Monday, November 7, 2011

Page 49: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

6

Monday, November 7, 2011

Page 50: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

Monday, November 7, 2011

Page 51: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

Evaluate a line eval_line

Monday, November 7, 2011

Page 52: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

Evaluate a line eval_line

Evaluate the next expression

logo_eval

Monday, November 7, 2011

Page 53: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

Evaluate a line eval_line

Evaluate the next expression

logo_eval

Monday, November 7, 2011

Page 54: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

Evaluate a line eval_line

Evaluate the next expression

logo_eval

Calls repeatedly

Monday, November 7, 2011

Page 55: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

? print 1 print 2

1

2

Evaluate a line eval_line

Evaluate the next expression

logo_eval

Calls repeatedly

Monday, November 7, 2011

Page 56: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

? print 1 print 2

1

2

Evaluate a line eval_line

Evaluate the next expression

logo_eval

Calls repeatedly

first call

second call

Argumentlogo_eval Effect

Monday, November 7, 2011

Page 57: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

? print 1 print 2

1

2

Evaluate a line eval_line

Evaluate the next expression

logo_eval

[ >> print, 1, print, 2 ]

Calls repeatedly

first call

second call

Argumentlogo_eval Effect

Monday, November 7, 2011

Page 58: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

? print 1 print 2

1

2

Evaluate a line eval_line

Evaluate the next expression

logo_eval

[ >> print, 1, print, 2 ]

Calls repeatedly

first call

second call

Argumentlogo_eval Effectprints 1, returns None

Monday, November 7, 2011

Page 59: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

? print 1 print 2

1

2

Evaluate a line eval_line

Evaluate the next expression

logo_eval

[ >> print, 1, print, 2 ]

Calls repeatedly

[ print, 1 >> print, 2 ]

first call

second call

Argumentlogo_eval Effectprints 1, returns None

Monday, November 7, 2011

Page 60: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Lines

Evaluating a line of Logo involves evaluating each expression

6

? print 1 print 2

1

2

Evaluate a line eval_line

Evaluate the next expression

logo_eval

[ >> print, 1, print, 2 ]

Calls repeatedly

[ print, 1 >> print, 2 ]

first call

second call

Argumentlogo_eval Effectprints 1, returns None

prints 2, returns None

Monday, November 7, 2011

Page 61: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

7

Monday, November 7, 2011

Page 62: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

7

Monday, November 7, 2011

Page 63: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

7

Monday, November 7, 2011

Page 64: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.

7

Monday, November 7, 2011

Page 65: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.

7

Monday, November 7, 2011

Page 66: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

7

Monday, November 7, 2011

Page 67: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

• A call expression is evaluated with apply_procedure.

7

Monday, November 7, 2011

Page 68: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

• A call expression is evaluated with apply_procedure.

7

def logo_eval(line, env):

Monday, November 7, 2011

Page 69: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

• A call expression is evaluated with apply_procedure.

7

def logo_eval(line, env): """Evaluate the first expression in a line."""

Monday, November 7, 2011

Page 70: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

• A call expression is evaluated with apply_procedure.

7

def logo_eval(line, env): """Evaluate the first expression in a line.""" token = line.pop()

Monday, November 7, 2011

Page 71: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

• A call expression is evaluated with apply_procedure.

7

def logo_eval(line, env): """Evaluate the first expression in a line.""" token = line.pop()The expression

form can be inferred from

the first token

Monday, November 7, 2011

Page 72: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

• A call expression is evaluated with apply_procedure.

7

def logo_eval(line, env): """Evaluate the first expression in a line.""" token = line.pop() if isprimitive(token):

The expression form can be

inferred from the first token

Monday, November 7, 2011

Page 73: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

• A call expression is evaluated with apply_procedure.

7

def logo_eval(line, env): """Evaluate the first expression in a line.""" token = line.pop() if isprimitive(token): return token

The expression form can be

inferred from the first token

Monday, November 7, 2011

Page 74: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

• A call expression is evaluated with apply_procedure.

7

def logo_eval(line, env): """Evaluate the first expression in a line.""" token = line.pop() if isprimitive(token): return token elif isvariable(token):

The expression form can be

inferred from the first token

Monday, November 7, 2011

Page 75: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Evaluation

The logo_eval function dispatches on expression form:

• A primitive expression is a word that can be interpreted as a number, True, or False. Primitives are self evaluating.

• A variable is looked up in the current environment.• A procedure definition creates a new user-defined procedure.• A quoted expression evaluates to the text of the quotation, which is a string without the preceding quote. Sentences are quoted and evaluate to themselves.

• A call expression is evaluated with apply_procedure.

7

def logo_eval(line, env): """Evaluate the first expression in a line.""" token = line.pop() if isprimitive(token): return token elif isvariable(token): ...

The expression form can be

inferred from the first token

Monday, November 7, 2011

Page 76: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

Monday, November 7, 2011

Page 77: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure

Monday, November 7, 2011

Page 78: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure

collect_argsEvaluate n operands

Monday, November 7, 2011

Page 79: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure

logo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

Monday, November 7, 2011

Page 80: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure Return the output value

logo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

Monday, November 7, 2011

Page 81: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure Return the output value

Return n arguments

logo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

Monday, November 7, 2011

Page 82: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure Return the output value

Return n arguments

Return the output valuelogo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

Monday, November 7, 2011

Page 83: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure Return the output value

Return n arguments

Return the output valuelogo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

[ print >> 2 ]

Monday, November 7, 2011

Page 84: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure Return the output value

Return n arguments

Return the output valuelogo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

[ print >> 2 ]

Popped by logo_eval

Monday, November 7, 2011

Page 85: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure Return the output value

Return n arguments

Return the output valuelogo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

[ print >> 2 ]

Popped by logo_eval

1. Collect 1 argument via logo_eval(collect_args)

Monday, November 7, 2011

Page 86: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure Return the output value

Return n arguments

Return the output valuelogo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

[ print >> 2 ]

Popped by logo_eval

[ print, 2 >> ]

1. Collect 1 argument via logo_eval(collect_args)

Monday, November 7, 2011

Page 87: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure Return the output value

Return n arguments

Return the output valuelogo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

[ print >> 2 ]

Popped by logo_eval

[ print, 2 >> ]

Popped by logo_eval also

(recursive call)

1. Collect 1 argument via logo_eval(collect_args)

Monday, November 7, 2011

Page 88: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Evaluating Call Expressions

8

apply_procedureApply a named procedure Return the output value

Return n arguments

Return the output valuelogo_applyApply a procedure toa sequence of arguments

collect_argsEvaluate n operands

[ print >> 2 ]

Popped by logo_eval

[ print, 2 >> ]

Popped by logo_eval also

(recursive call)

1. Collect 1 argument via logo_eval(collect_args)

2. Apply print procedure to the argument '2'(logo_apply)

Monday, November 7, 2011

Page 89: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Procedures

9

Monday, November 7, 2011

Page 90: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Procedures

9

class Procedure():

Monday, November 7, 2011

Page 91: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Procedures

9

class Procedure():

def __init__(self, name, arg_count, body, isprimitive=False,

needs_env=False, formal_params=None):

Monday, November 7, 2011

Page 92: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Procedures

9

class Procedure():

def __init__(self, name, arg_count, body, isprimitive=False,

needs_env=False, formal_params=None):

self.name = name

self.arg_count = arg_count

self.body = body

self.isprimitive = isprimitive

self.needs_env = needs_env

self.formal_params = formal_params

Monday, November 7, 2011

Page 93: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Procedures

9

class Procedure():

def __init__(self, name, arg_count, body, isprimitive=False,

needs_env=False, formal_params=None):

self.name = name

self.arg_count = arg_count

self.body = body

self.isprimitive = isprimitive

self.needs_env = needs_env

self.formal_params = formal_params

def logo_apply(proc, args):

"""Apply a Logo procedure to a list of arguments."""

Monday, November 7, 2011

Page 94: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Procedures

9

class Procedure():

def __init__(self, name, arg_count, body, isprimitive=False,

needs_env=False, formal_params=None):

self.name = name

self.arg_count = arg_count

self.body = body

self.isprimitive = isprimitive

self.needs_env = needs_env

self.formal_params = formal_params

def logo_apply(proc, args):

"""Apply a Logo procedure to a list of arguments."""

if proc.isprimitive:

return proc.body(*args)

Monday, November 7, 2011

Page 95: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Procedures

9

class Procedure():

def __init__(self, name, arg_count, body, isprimitive=False,

needs_env=False, formal_params=None):

self.name = name

self.arg_count = arg_count

self.body = body

self.isprimitive = isprimitive

self.needs_env = needs_env

self.formal_params = formal_params

def logo_apply(proc, args):

"""Apply a Logo procedure to a list of arguments."""

if proc.isprimitive:

return proc.body(*args)

else:

"""Apply a user-defined procedure"""

Monday, November 7, 2011

Page 96: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter

10

Apply

Eval

Monday, November 7, 2011

Page 97: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter

10

Apply

Evaleval_line

logo_eval

Monday, November 7, 2011

Page 98: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Logo Interpreter

10

Apply

Evaleval_line

logo_eval

apply_procedure

collect_args

logo_apply

Monday, November 7, 2011

Page 99: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Eval/Apply in Lisp 1.5

11

Monday, November 7, 2011

Page 100: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Eval/Apply in Lisp 1.5

11

Monday, November 7, 2011

Page 101: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Eval/Apply in Logo

12

Apply

eval_line

apply_procedure

collect_args

logo_apply

Eval

logo_eval

Monday, November 7, 2011

Page 102: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Eval/Apply in Logo

12

Apply

eval_line

apply_procedure

collect_args

logo_apply

Eval

logo_eval

Call expressions

Monday, November 7, 2011

Page 103: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Eval/Apply in Logo

12

Apply

eval_line

apply_procedure

collect_args

logo_apply

Eval

logo_eval

Call expressions

Operand expressions

Monday, November 7, 2011

Page 104: 61A Lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61A Lecture 29 Monday, November 7 Monday, November 7, 2011. Homework: Huffman Encoding Trees 2 ... Huffman Encoding Trees Efficient

Eval/Apply in Logo

12

Apply

eval_line

apply_procedure

collect_args

logo_apply

Eval

logo_eval

Call expressions User-defined

procedures

Operand expressions

Monday, November 7, 2011