CS 61A lect2
CS61A lect2
Anatomy of a Call Expression:operator, operand
add ( 2 , 3 )
Operator Operand Operand
Operators and operands are also expressions
Evaluation procedure for call expressions:
- Evaluate the operator and then the operand subexpressions
- Apply the function that is the value of the operator
to the arguments that are the values of the operands
Execution rule for assignment statements:
- Evaluate all expressions to the right of = from left to right.
- Bind all names to the left of = to those resulting values in the current frame.
Execution procedure for def statements:
- Create a function with signature
<name>(<formal parameters>) - Set the body of that function to be everything indented after the first line
- Bind
<name>to that function in the current frame
- Bind
Procedure for calling/applying user-defined functions (version 1):
- Add a local frame, forming a new environment
- Bind the function’s formal parameters to its arguments in that frame
- Execute the body of the function in that new environment
Most important two things I’ll say all day:
- An environment is a sequence of frames.
- A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
Exercise:
What is the value of the final expression in this sequence?
f = min
f = max
g, h = min, max
max = g
max(f(2, g(h(1, 5), 3)), 4)
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
