SICP Exercise 2.46 make-vect

Exercise 2.46.  A two-dimensional vector v running from the origin to a point can be represented as a pair consisting of an x-coordinate and a y-coordinate. Implement a data abstraction for vectors by giving a constructor make-vect and corresponding selectors xcor-vect and ycor-vect. In terms of your selectors and constructor, implement procedures add-vectsub-vect, and scale-vect that perform the operations vector addition, vector subtraction, and multiplying a vector by a scalar:


SOLUTION


The code and tests are here.

Comments

Popular posts from this blog

SICP Exercise 4.9 do for while until

SICP Exercise 3.56 merge streams

SICP Exercise 4.14 map as compound vs. primitive type