正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Data abstractions for lines Similarly, we can glue two endpoints or vectors together to eate a line segment. T data abstractie contract between the constructor (make-segment)and (define p1((make-vect 2 3) the selectors(start-segment and end p1)→3 segment (define p2 (make-vect 5 4)) So this gives us a way of abstracting vectors and segments Define s1 tmake-segmentp1 p2" Note the key point: I don' t need to know the details of how Ixcor tstart-segment s 1>2 vectors and segments are built, I just rely on the contract.This lycor tend-segment s ))>4 means we could think of George in terms of the appropriate elements, namely lines, rather than details of how those lines are represented Slide 30.1.l1 a better George So here is george in this format. Now, it looks like we have just put some window dressing around the line segments. But hang ta mm pf mahe wd 由mnr9-11m on, as we will see how treating George as an abstraction is going to make life much easier for us. In particular, note that fmet here we have created an abstraction for the points, and a separate abstraction for the line segments. Moreover, these are mm w omarm now defined with respect to some coordinate frame, they are not actually being drawn yet. So we have also separated the act mm l mrm of drawing from the representation of the data to be drawn dtn p22 trau veet.,》》 6 001 SICP Slide 30.1.12 Gluing things together First though, how could we actually build these vectors and For pairs, use a cons: 凵 Well, you saw this in the last lecture. For pairs of things (i.e things that come naturally in twos), we could just use a cons For larger structures. use a list: cell or a pair. And for larger collections, we could use lists. And of courses lists are just sequences of cons cells glued together into a spine, with the elements hanging off of it. ist1234) (cons I(cons 2(cons 3(cons d niD)))6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 30.1.10 Similarly, we can glue two endpoints or vectors together to create a line segment. This again is a data abstraction, with a contract between the constructor (make-segment) and the selectors (start-segment and end￾segment). So this gives us a way of abstracting vectors and segments. Note the key point: I don't need to know the details of how vectors and segments are built, I just rely on the contract. This means we could think of George in terms of the appropriate elements, namely lines, rather than details of how those lines are represented. Slide 30.1.11 So here is George in this format. Now, it looks like we have just put some window dressing around the line segments. But hang on, as we will see how treating George as an abstraction is going to make life much easier for us. In particular, note that here we have created an abstraction for the points, and a separate abstraction for the line segments. Moreover, these are now defined with respect to some coordinate frame; they are not actually being drawn yet. So we have also separated the act of drawing from the representation of the data to be drawn. Slide 30.1.12 First though, how could we actually build these vectors and segments? Well, you saw this in the last lecture. For pairs of things (i.e. things that come naturally in twos), we could just use a cons cell or a pair. And for larger collections, we could use lists. And of courses lists are just sequences of cons cells glued together into a spine, with the elements hanging off of it
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有