Data abstraction divides a data type into two pieces: an interface and an implementation. The most efficient representation is often a lot more difficult to implement, so we may wish to develop a simple implementation first and only change to more efficient representation if it proves critical to the overall performance of a system.If we decide to change the representation of some data for any reason, we must be able to locate all parts of a program that are dependent on the representation.This is accomplished using the technique of data abstraction. We may also decide to change the representation of the data. The representation of these entities is often complex, so we do not want to be concerned with their details when we can avoid them. (list (number-leaves (rson bintree)) (lson bintree)))))))Įvery time we decide to represent a certain set of quantities in a particular way,we are defining a new data type: the data type whose values are those representations and whoes operations are the procudures that manipulate those entities. (list (+ 1 n) (contents-of bintree) (number-leaves (lson bintree))) (_path var (lson bst) (append p (list 'left))))))) (else (if (> var (contents-of bst)) (_path var (rson bst) (append p (list 'right))) (and (integer? (car bintree)) (null? (cadr bintree)) (null? (caddr bintree))))) bintree grammar :Bintree::=Int |(Symbol Bintree Bintree) (else (list (car lst) (up (cdr lst))))))) ((list? (car lst)) (list (up (car lst)) (up (cdr lst)))) ((pred (car lst)) (every? pred (cdr lst))) ((pred (car lst)) (cons (car lst) (filter-in pred (cdr lst)))) (cons (list (car sos1) (car sos2)) (product (cdr sos1) (cdr sos2)))))) (else (+ 0 (count-occurrences s (cdr lst)))))))
((eqv? s (car lst)) (+ 1 (count-occurrences s (cdr lst)))) (cons (car lst) (list-set (cdr lst) (- n 1) x))))) (cons (list (cadar lst) (caar lst)) (invert (cdr lst)))))) When defining a procedure that operates on inductively defined data, the structure of the program should be patterned after the structure of the data. (plus (mul n (fact (predecessor n)))))))) ((iszero? (predecessor n)) (successor zero)) (else (plus y (mul (predecessor x) y))))))
(predecessor (successor (successor (successor zero)))) nonegative integers with the given base.
message-accepting object so that we can represent the Let us encapsulate the operations of the interface into a