正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 9.1. 19 To summarize we have introduced the idea of tagged data Benefits of tagged data types, and used that to consider clean ways to modularize data-directed program systems. We now want to explore in more detail how using functions that decide what to do based on the arguments tagged data makes it easier to build large systems ole: in a graphics program functions that fail gracefully if given bad arguments . much better to give an error message that 6001 SICP 6.001 Notes: Section 9. 2 Slide 9.2.1 Example: Arithmetic evaluation To show how to use these two ideas: data directed programming and defensive programming, the rest of this lecture is going to (define expl (make-sum (make-sum 3 15)20) consider an extended example. Because this example involves expl 仆+(+315}20 fair amount of code, it is important to keep in mind the key points being illustrated, so you don,'t lose sight of them amidst all the code fragments. To make this easier, we are going to incremental build new versions of the example on top of simpler versions, thus highlight key ideas and changes The example we are going to use to illustrate the ideas of data directed programming and defensive programming is a system 6001 sICP to manipulate arithmetic expressions. This will be similar to our example of symbolic derivatives, but now applying to more general expressions. So what does this mean? Not only do i want to be able to create symbolic arithmetic expressions, using appropriate constructors, I also want to be able to reduce those expressions to simpler forms, whenever possible. Thus, I would like to create symbolic expressions, such as exp l, as shown. Thus the value of the exp l will be the actual expression. And, I want to create a system that can evaluate expressions such as expl, that is, reduce this expression to a simpler form, in this case, the simpler expression 3 86.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 9.1.19 To summarize, we have introduced the idea of tagged data types, and used that to consider clean ways to modularize systems. We now want to explore in more detail how using tagged data makes it easier to build large systems. 6.001 Notes: Section 9.2 Slide 9.2.1 To show how to use these two ideas: data directed programming and defensive programming, the rest of this lecture is going to consider an extended example. Because this example involves a fair amount of code, it is important to keep in mind the key points being illustrated, so you don't lose sight of them amidst all the code fragments. To make this easier, we are going to incremental build new versions of the example on top of simpler versions, thus highlight key ideas and changes. The example we are going to use to illustrate the ideas of data directed programming and defensive programming is a system to manipulate arithmetic expressions. This will be similar to our example of symbolic derivatives, but now applying to more general expressions. So what does this mean? Not only do I want to be able to create symbolic arithmetic expressions, using appropriate constructors, I also want to be able to reduce those expressions to simpler forms, whenever possible. Thus, I would like to create symbolic expressions, such as exp1, as shown. Thus the value of the exp1 will be the actual expression. And, I want to create a system that can evaluate expressions such as exp1, that is, reduce this expression to a simpler form, in this case, the simpler expression 38
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有