
Replies:
0

Pages:
1



Posts:
26
From:
US
Registered:
11/11/10



Problem with discussion of ratio
Posted:
Nov 13, 2010 5:42 PM


Clojure does define one more type of number – the ratio. Ratios are created when two integers are divided such that they can’t be reduced any further. Here’s an example – executing the code (/ 4 9) returns a ratio object 4/9. If instead of dividing such integers, one of the numbers is a Double, then the result is also a double. As an example, evaluating (/ 4.0 9) returns 0.4444444444444444.
That "such integers" thing is really unclear. I think what you mean is something like "If you divide two integers, the result will be a ratio. If, however, either of the arguments to the division operator is a floatingpoint number, then a floating point number will be returned instead of an integer."
I think this whole section could use a substantial extension. It implicitly assumes that your reader will know the Java type system (what about a sidebar explaining the Java type system, at least where the numbers are concerned?). It also uses the term "boxed," which has never been defined. I'm familiar with the "boxed/unboxed" distinction from lisp, but it's a bit of an advanced topic there, since the distinction is not made visible to the programmer the way it is in Java. Worrying about boxed numbers is something that you get around to when you are optimizing your lisp code.
I think another way to clarify the discussion would be to introduce the "exact/inexact" distinction, and not to assume that the reader will necessarily understand that distinction. Lots of programmers don't think too hard about the fact that floating point numbers aren't exact (partly because their programming languages don't provide exact representations).
Exact and inexact is a distinction that will help the reader understand the way clojure rolls over from shorter integers to bignums, etc.



Legend


Gold: 300
+
pts


Silver: 100
 299
pts


Bronze: 25
 99
pts


Manning Author


Manning Staff


Manning Developmental Editor

