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

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

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

Lecture 22 Macros Chris Allsman

Lecture 22 - Macros Chris Allsman

Macrosns ⊙

Mac OS Macros Macron Macarons Macaroni

Announcements ●HW6out,due Tues8/6 ●Proj4,Scheme out o Phase I/ll due Mon 8/5 o Whole project due Fri 8/9 o 1 EC point by submitting Thurs 8/8 11:59 PM PDT Midterm Regrades due 8/1

Announcements ● HW6 out, due Tues 8/6 ● Proj4, Scheme out ○ Phase I/II due Mon 8/5 ○ Whole project due Fri 8/9 ○ 1 EC point by submitting Thurs 8/8 11:59 PM PDT ● Midterm Regrades due 8/1

Review:Interpreters Representing Expressions

Review: Interpreters & Representing Expressions

Read-Eval-Print Loop (REPL) Read Lexer ..expression... value output Eval Print ,,。… input representation string string …tokens: Parser 。..年gg年。。。。。。 “(+12)” +12N 3 ["(",,“+”,1,2,“)",]Pair("+”,Pair(1,Pair(2,ni1))

input string value expression representation Read-Eval-Print Loop (REPL) Read Eval Print output string Lexer Parser tokens “(+ 1 2)” + 1 2 3 [“(“, “+”, 1, 2, “)”, ] Pair(“+”, Pair(1, Pair(2, nil)))

Demo Representing Expressions o In Scheme,we can create lists that "look like"combinations o In fact,in Scheme,expressions are lists (or primitive values) Quoting prevents evaluation of an expression Calling eval on an unevaluated expression will evaluate that value scm>‘(+12) scm>(list quotient 10 2) (+12) (quotient 10 2) scm>(eva1'(+12)) scm>(eval (list quotient 10 2)) 3 5

Representing Expressions ● In Scheme, we can create lists that “look like” combinations ○ In fact, in Scheme, expressions are lists (or primitive values) ● Quoting prevents evaluation of an expression ● Calling eval on an unevaluated expression will evaluate that value Demo scm> ‘(+ 1 2) (+ 1 2) scm> (eval ‘(+ 1 2)) 3 scm> (list 'quotient 10 2) (quotient 10 2) scm> (eval (list 'quotient 10 2)) 5

Expressions In Scheme

Expressions In Scheme

Demo Expressions As Data Recall:programs are composed of expressions,but manipulate values or data In Scheme,expressions are either primitive expressions or lists which means they're also a form of data! This means we can: Assign expressions to variables ● Pass expressions into functions Create return new expressions within functions

Expressions As Data Recall: programs are composed of expressions, but manipulate values or data In Scheme, expressions are either primitive expressions or lists - which means they’re also a form of data! This means we can: ● Assign expressions to variables ● Pass expressions into functions ● Create & return new expressions within functions Demo

Begin Demo begin is a special form takes in any number of expressions, evaluates them in order,and evaluates to the value of the final expression (begin 3 2 1) scm>(begin (define x 2)(define x (x 1))x) 3

Begin begin is a special form takes in any number of expressions, evaluates them in order, and evaluates to the value of the final expression Demo (begin 3 2 1) 1 scm> (begin (define x 2) (define x (+ x 1)) x) 3

Let Demo (let ((symbol1 expr1) Each symbol is bound to the value of the expression (symbo12 expr2) in parallel …) Evaluate to the value of the The bindings only exist when body body using the binding evaluating the body scm>(1et((x2) (y3) (+xy)) 5

Let (let ((symbol1 expr1) (symbol2 expr2) …) body) Demo scm> (let ((x 2) (y 3)) (+ x y)) 5 Each symbol is bound to the value of the expression in parallel Evaluate to the value of the body using the binding The bindings only exist when evaluating the body

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