in Books, Concrete Abstractions, Doing Books

Concrete Abstractions: Chapter 6

Exercise 6.23
A three-dimensional (3D) vector has x, y, and z coordinates, which are numbers. 3D vectors can be constructed and accessed using the following abstract interface:

(make-3D-vector x y z)
(x-coord vector)
(y-coord vector)
(z-coord vector)

a. Using this abstract interface, define procedures for adding two vectors, finding the dot-product of two vectors, and scaling a vector by a numerical scaling factor.
b. Choose a representation for vectors and implement make-3D-vector, x-coord, y-coord, and z-coord.

Solution: a.

b.

This was a quite short chapter. However chapter 7 is rather long. This exercise above covers pretty much the whole chapter, it was just about cons, car and cdr.

Write a Comment

Comment