61a lecture 29 - inst.eecs.berkeley.educs61a/fa11/61a...61a lecture 29 monday, november 7 monday,...
TRANSCRIPT
61A Lecture 29
Monday, November 7
Monday, November 7, 2011
Homework: Huffman Encoding Trees
2
Monday, November 7, 2011
Homework: Huffman Encoding Trees
Efficient encoding of strings as ones and zeros (bits).
2
Monday, November 7, 2011
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
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
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
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
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
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
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
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
Logo Refresher
3
Monday, November 7, 2011
Logo Refresher
Data types: Words and sentences (immutable sequences)
3
Monday, November 7, 2011
Logo Refresher
Data types: Words and sentences (immutable sequences)
Syntactic forms: Call expressions, literals, and to-statements
3
Monday, November 7, 2011
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
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
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
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
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
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
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
Logo Interpreter Architecture
4
Monday, November 7, 2011
Logo Interpreter Architecture
4
parser
Monday, November 7, 2011
Logo Interpreter Architecture
4
parser Evaluator
Monday, November 7, 2011
Logo Interpreter Architecture
4
parser Evaluator
Monday, November 7, 2011
Logo Interpreter Architecture
4
string parser Evaluator
Monday, November 7, 2011
Logo Interpreter Architecture
4
string parser Evaluator
'run [print sum 1 2]'
Monday, November 7, 2011
Logo Interpreter Architecture
4
string parser line Evaluator
'run [print sum 1 2]'
Monday, November 7, 2011
Logo Interpreter Architecture
4
string parser line Evaluator
'run [print sum 1 2]' ['run', ['print', 'sum', '1', '2']]
Monday, November 7, 2011
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
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
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
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
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
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
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
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
Tracking Positions in Lines
5
Monday, November 7, 2011
Tracking Positions in Lines
A line is used up as it is evaluated
5
Monday, November 7, 2011
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
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
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
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
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
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
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
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
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
Evaluating Lines
6
Monday, November 7, 2011
Evaluating Lines
Evaluating a line of Logo involves evaluating each expression
6
Monday, November 7, 2011
Evaluating Lines
Evaluating a line of Logo involves evaluating each expression
6
Evaluate a line eval_line
Monday, November 7, 2011
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
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
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
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
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
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
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
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
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
Logo Evaluation
7
Monday, November 7, 2011
Logo Evaluation
The logo_eval function dispatches on expression form:
7
Monday, November 7, 2011
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
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
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
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
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
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
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
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
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
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
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
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
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
Evaluating Call Expressions
8
Monday, November 7, 2011
Evaluating Call Expressions
8
apply_procedureApply a named procedure
Monday, November 7, 2011
Evaluating Call Expressions
8
apply_procedureApply a named procedure
collect_argsEvaluate n operands
Monday, November 7, 2011
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
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
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
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
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
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
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
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
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
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
Procedures
9
Monday, November 7, 2011
Procedures
9
class Procedure():
Monday, November 7, 2011
Procedures
9
class Procedure():
def __init__(self, name, arg_count, body, isprimitive=False,
needs_env=False, formal_params=None):
Monday, November 7, 2011
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
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
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
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
Logo Interpreter
10
Apply
Eval
Monday, November 7, 2011
Logo Interpreter
10
Apply
Evaleval_line
logo_eval
Monday, November 7, 2011
Logo Interpreter
10
Apply
Evaleval_line
logo_eval
apply_procedure
collect_args
logo_apply
Monday, November 7, 2011
Eval/Apply in Lisp 1.5
11
Monday, November 7, 2011
Eval/Apply in Lisp 1.5
11
Monday, November 7, 2011
Eval/Apply in Logo
12
Apply
eval_line
apply_procedure
collect_args
logo_apply
Eval
logo_eval
Monday, November 7, 2011
Eval/Apply in Logo
12
Apply
eval_line
apply_procedure
collect_args
logo_apply
Eval
logo_eval
Call expressions
Monday, November 7, 2011
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
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