中国高校课件下载中心 》 教学资源 》 大学文库

南京大学:《计算机程序的构造和解释 Structure and Interpretation of Computer Programs》课程教学资源(PPT课件讲稿)02-Names & Functions

文档信息
资源类别:文库
文档格式:PPTX
文档页数:22
文件大小:1.1MB
团购合买:点击进入团购
内容简介
南京大学:《计算机程序的构造和解释 Structure and Interpretation of Computer Programs》课程教学资源(PPT课件讲稿)02-Names & Functions
刷新页面文档预览

Lecture 2 Names Functions 09/25 Slides adapted from Berkeley CS61a

Lecture 2 - Names & Functions 09/25 Slides adapted from Berkeley CS61a

Program Structure

Program Structure

Review-Expressions Primitive Expressions: 2 “he11o!" add numbers strings names Arithmetic Expressions: 1+2 15//3 add(3,4) Call Expressions: max(add(2,3),5*min(-1,4))

Review - Expressions Primitive Expressions: Call Expressions: 2 “hello!” add add(3, 4) max(add(2, 3), 5 * min(-1, 4)) Arithmetic Expressions: 1 + 2 15 // 3 numbers strings names

Review-Evaluating Call Expressions add (2 ,3 Operator Operand Operand 1.Evaluate a.Evaluate the operator subexpression b.Evaluate each operand subexpression 2.Apply a.Apply the value of the operator subexpression to the values of the operand subexpression

Review - Evaluating Call Expressions 1. Evaluate a. Evaluate the operator subexpression b. Evaluate each operand subexpression 2. Apply a. Apply the value of the operator subexpression to the values of the operand subexpression add ( 2 , 3 ) Operator Operand Operand

Nested Call Expression Evaluate operator Evaluate operands 3 Apply! 45 add(add(6,mu1(4,6),mu1(3,5)) add 30 15 add(6,mu1(4,6)) mu1(3,5) 24 add 6 mu1(4,6) mul 3 5 mul 4 6 Expression Tree

Nested Call Expression Evaluate operator Evaluate operands Apply! add(add(6, mul(4, 6)), mul(3, 5)) add 1 2 3 add(6, mul(4, 6)) add 6 mul(4, 6) mul 4 6 24 30 mul(3, 5) 15 mul 3 5 45 Expression Tree

Values Programs manipulate values Values represent different types of data Integers:2 44-3 Strings:“hello!”“cs61a” Floats:3.144.5-2.0 Booleans:True False

Values Programs manipulate values Values represent different types of data Floats: Integers: Strings: Booleans: 2 44 -3 3.14 4.5 -2.0 “hello!” “cs61a” True False

Expressions Values Expressions evaluate to values in one or more steps Expression: Value: he11o!' 'hello!' 7/2 3.5 add(1,max(2,3)) 4

Expressions & Values Expressions evaluate to values in one or more steps ‘hello!’ 7 / 2 3.5 add(1, max(2, 3)) 4 Expression: ‘hello!’ Value:

Names Demo Values can be assigned to names to make referring to them easier. A name can only be bound to a X single value. One way to introduce a new name in a program is with an assignment statement. ×=1+2*3-4//5 Name Expression Statements affect the program,but do not evaluate to values

Names Values can be assigned to names to make referring to them easier. A name can only be bound to a single value. Demo One way to introduce a new name in a program is with an assignment statement. x = 1 + 2 * 3 - 4 // 5 Name Expression 7 x Statements affect the program, but do not evaluate to values

Check Your Understanding >>f min >>>f= max >>g,h min, max >>> max g >>>max(f(2,g(h(1,5),3)),4) ???

Check Your Understanding >>> f = min >>> f = max >>> g, h = min, max >>> max = g >>> max(f(2, g(h(1, 5), 3)), 4) ???

Visualizing Assignment Demo Names are bound to values in an environment Global frame 1X=1 X 2y=2 Final Value 3X=y*2 Name To execute an assignment statement: Bindings 1.Evaluate the expression to the right of = 2.Bind the value of the expression to the name to the left of in the current environment

Visualizing Assignment Names are bound to values in an environment To execute an assignment statement: 1. Evaluate the expression to the right of =. 2. Bind the value of the expression to the name to the left of = in the current environment. Final Value Bindings Name Demo

共22页,试读已结束,阅读完整版请下载
刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档