正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 10.3.6 Table1 example And then we use this new operation, set-cdr! to take the cons (define ttl (make-tablel)) air pointed to by ttl, and mutate or change it's cdr to point to (tablel-put! tt1 'y 20) this new structure, that is to the value returned by add -assoc Notice what this gives us. We now have a new table. It has a tag or the front, and it has an a-list at the back, which currently has one binding within it table1 Slide 10.3.7 Let's add another binding, x and 15, to this same table (define ttl (make-tablel)) (tablel-put! tt1 'y 20) (tablel-put! ttl 'x 15) Slide 10.3.8 Table1 example Looking back at the code, you can see what this should do. Add- (define ttl (make-tablel)) assoc first takes the internal representation for the table(i.e (tablel- removes the tag) getting access to the structure shown in blue. It (tablel-put! t七1 15 then creates a new binding, a pairing of x and 15, creating a 2 七t1 element list, and then"conses"this onto the front of the existing a- st. This is shown in red. This new structure is our new a-list and it has within it two bindings, each a separate 2 element list 七ab1e1 Slide 10.3.9 Then we once more use the set-cdr! operation to take the pairTable1 example pointed to by ttl and change its cdr part to point to the value define ttl (make-tablel)) returned by add-assoc, i.e., this new structure. This gives us a (tablel-put! ttl 'y 20) new a-list associated with this tabl tablel6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 10.3.6 And then we use this new operation, set-cdr! to take the cons pair pointed to by tt1, and mutate or change it's cdr to point to this new structure, that is to the value returned by add-assoc. Notice what this gives us. We now have a new table. It has a tag on the front, and it has an a-list at the back, which currently has one binding within it. Slide 10.3.7 Let's add another binding, x and 15, to this same table. Slide 10.3.8 Looking back at the code, you can see what this should do. Add￾assoc first takes the internal representation for the table (i.e. removes the tag) getting access to the structure shown in blue. It then creates a new binding, a pairing of x and 15, creating a 2 element list, and then "conses" this onto the front of the existing a￾list. This is shown in red. This new structure is our new a-list, and it has within it two bindings, each a separate 2 element list. Slide 10.3.9 Then we once more use the set-cdr! operation to take the pair pointed to by tt1 and change its cdr part to point to the value returned by add-assoc, i.e., this new structure. This gives us a new a-list associated with this table
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有