6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 8.1.1 a useful property of the quote special form In fact, our Scheme evaluator is smart, and it keeps track of list (quote delta) (quote delta)) what symbols have been created so far. As a consequence, when we refer to a symbol, Scheme gives us a pointer to the unique instance of that symbol. We can illustrate that as shown, by evaluating this ex This will create a list of two elements, both of which happen to be the symbol delta 4 Slide 8.1.19 A useful property of the quote special form Scheme will create a box-and-pointer structure for a two- element list. But the car of both cons pairs in this list now (list (quote delta) (quote delta)) point to exactly the same object inside of the machine, namely the data structure for the symbol delta symbol delta A useful property of the quote special form Slide 8.1. 20 This is valuable, because it gives us a way of creating (list (quote delta) (quote delta) predicates for testing equality of symbols, and indeed other more complicated objects, as we will see a bit later on symbol delta Two quote expressions with the same name return the same Slide 8. 1.21 The operation eq? tests for the same object Our predicate for testing equality of symbols is eg? This is a very powerful procedure, used to test equality of a range of returns #t if its two arguments are the same object structures, as we will see. Ea? is a primitive procedure (i.e something built into Scheme), and it returns the boolean value true"if its two arguments are the same object. For our context, that says that since we create only one instance of each symbol using eq? to test equality of symbols will return true if the two expressions evaluate to a pointer to the same symbol data structure 600SC
6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 8.1.18 In fact, our Scheme evaluator is smart, and it keeps track of what symbols have been created so far. As a consequence, when we refer to a symbol, Scheme gives us a pointer to the unique instance of that symbol. We can illustrate that as shown, by evaluating this expression. This will create a list of two elements, both of which happen to be the symbol delta. Slide 8.1.19 Scheme will create a box-and-pointer structure for a twoelement list. But the car of both cons pairs in this list now point to exactly the same object inside of the machine, namely the data structure for the symbol delta. Slide 8.1.20 This is valuable, because it gives us a way of creating predicates for testing equality of symbols, and indeed other more complicated objects, as we will see a bit later on. Slide 8.1.21 Our predicate for testing equality of symbols is eq?. This is a very powerful procedure, used to test equality of a range of structures, as we will see. Eq? is a primitive procedure (i.e. something built into Scheme), and it returns the Boolean value "true" if its two arguments are the same object. For our context, that says that since we create only one instance of each symbol, using eq? to test equality of symbols will return true if the two expressions evaluate to a pointer to the same symbol data structure
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 8.1.22 The operation eq? tests for the same object Here is an example of what we mean by that. If we apply eg a primitive procedure returns #t if its two arguments are the same object to two arguments that evaluate to the same symbol, we get a very fast true" value returned otherwise a "false" value is returned ote e te delta)(quote eps))==> Slide 8.1.23 The operation eq? tests for the same object Finally, here is the type of eq? It accepts two arguments of a primitive procedure any type other than a number or a string, and returns a boolean returns #t if its two arguments are the same object value. based on the rules described above (eq? s)(cue e delta) For those who are interested otype, EQtype b。o1ea e= any type except number or string The operation eq? tests for the same object Slide 8.1.24 For numbers, we have a separate procedure to test equality, and if its two arguments are the same object a different procedure to testing equality of strings. Everything very fast else uses eq? (eg? (quote eps)(quote ep te delta)(quote ->#t This now completes our method for creating and dealing with )==> eq?: E&type, etype boolean i Etype any type except number or string 6.001 Notes: Section 8.2
6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 8.1.22 Here is an example of what we mean by that. If we apply eq? to two arguments that evaluate to the same symbol, we get a "true" value returned, otherwise a "false" value is returned. Slide 8.1.23 Finally, here is the type of eq?. It accepts two arguments of any type other than a number or a string, and returns a Boolean value, based on the rules described above. Slide 8.1.24 For numbers, we have a separate procedure to test equality, and a different procedure to testing equality of strings. Everything else uses eq?. This now completes our method for creating and dealing with symbols. 6.001 Notes: Section 8.2