We are presented with some coercion functions and asked
Ex 4.1: Why is inchToPixel x not defined as 100 * round
It is instead defined as round(100 * x). This is because if
rounding was done on the input parameter, then whether it was, say, 1.01
or 1.99, the answer would be the same: 100*(round 1.01) = 100*1 = 100.
Ex 4.2 Why is pixelToInch n not defined as intToFloat
Similarly, this is to do with fixity/order of application of
expressions: The version above would first try to evaluate
n/100, which will fail, as n is an Integer, and
â€œ/â€œ isn't defined for Ints.
That's it for the exercises. I played along with the examples, which
basically amounts to copying out of the book – actually I think that's
more instructive than just reading or getting the source code off the
internet, because it helps develop finger-memory.
Well, he does leave a â€œyou may wish to define these functions on your
own as an exerciseâ€, but right now, I'm going to bed instead.