当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

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

资源类别:文库,文档格式:PPTX,文档页数:24,文件大小:2.37MB,团购合买
点击下载完整版文档(PPTX)

474NS)PROGRAMMING YOU FORGOT TO PUT PARENTHESSS ACTER MAIN. Lecture 20-More Scheme Chris Allsman MAE PARENS. &

Lecture 20 - More Scheme Chris Allsman

Lis(t)P(rocessing) s7% APR CALIFORNIA☑ CAR CDR LEY ENGINEERING 3

Lis(t) P(rocessing)

Scheme List Definition A Scheme list is either: nil Composed of a first element(car)and the rest(cdr)of the Scheme list Value of car is the 2 3 number 1 List terminated with nil car cdr car cdr car cdr cdr contains a pointer to a linked list

Scheme List Definition A Scheme list is either: ● nil ● Composed of a first element (car) and the rest (cdr) of the Scheme list 1 2 3 car cdr car cdr car cdr Value of car is the number 1 cdr contains a pointer to a linked list List terminated with nil

Creating Scheme Lists Demo 2 3 car cdr car cdr car cdr (cons 1 (cons1(cons2 ) (cons 1 (cons 2 (cons 3 nil))

Creating Scheme Lists 1 2 3 car cdr car cdr car cdr (cons 1 __________________________________) (cons 1 (cons 2 _________________________)) (cons 1 (cons 2 (cons 3 nil)) Demo

Scheme Lists vs.Linked Lists Scheme Lists: Linked Lists: (cons a b) Link(a,b) (car Ist) Ist.first (cdr Ist) Ist.rest nil Link.empty (1(23) >

Scheme Lists vs. Linked Lists Scheme Lists: (cons a b) (car lst) (cdr lst) nil (1 (2 3)) Linked Lists: Link(a, b) lst.first lst.rest Link.empty >

Checking Equivalence Demo (equal?e1 e2)checks if el and e2 evaluate to equivalent values ●Like=in Python ●(null?expr)is like(equal?expr ni1) (eq?e1 e2)checks if el and e2 evaluate to identical values ●Like is in Python Only matters for lists (e1 e2)only works for numbers

Checking Equivalence (equal? e1 e2) checks if e1 and e2 evaluate to equivalent values ● Like == in Python ● (null? expr) is like (equal? expr nil) (eq? e1 e2) checks if e1 and e2 evaluate to identical values ● Like is in Python ● Only matters for lists (= e1 e2) only works for numbers Demo

List Constructor Demo If we know each element we want to put in a list,we can use the list constructor The list constructor takes in any number of elements and puts each element as a single element in a list scm> (1ist123) scm>(list 0 (list 1 2 3)) (123) (0(123) 123 123N

List Constructor If we know each element we want to put in a list, we can use the list constructor The list constructor takes in any number of elements and puts each element as a single element in a list scm> (list 1 2 3) (1 2 3) scm> (list 0 (list 1 2 3)) (0 (1 2 3)) 1 2 3 1 2 3 0 Demo

Quoting Demo The quote special form takes in a single argument and returns an unevaluated version of the argument Quoting a symbol gives a symbol back,that symbol can mean something to scheme! Quoting the representation of a list gives a list scm>‘(abc) scm>‘(0(123)) (a b c) (8(123)) 123N

Quoting The quote special form takes in a single argument and returns an unevaluated version of the argument Quoting a symbol gives a symbol back, that symbol can mean something to scheme! Quoting the representation of a list gives a list scm> ‘(a b c) (a b c) scm> ‘(0 (1 2 3)) (0 (1 2 3)) a b c 1 2 3 0 Demo

Example-Add To End Given a scheme list,Ist,and an element,x,add x to the end of Ist (define (add-to-end lst x) scm> (add-to-end nil 1) (1) scm> (add-to-end (1 2)3) (123) scm> (add-to-end‘(123)‘(4)) (123(4))

Example - Add To End Given a scheme list, lst, and an element, x, add x to the end of lst (define (add-to-end lst x) ) scm> (add-to-end nil 1) (1) scm> (add-to-end ‘(1 2) 3) (1 2 3) scm> (add-to-end ‘(1 2 3) ‘(4)) (1 2 3 (4))

Using List Constructors

Using List Constructors

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

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有