-
Page 12
In the first paragraph, last sentence, replace:
This combine method is somewhat equivalent
with:
This fill method is somewhat equivalent
-
Page 24
In the last paragraph, second sentence, replace:
To make it a function, you could test the second parameter and return a value if
it’s null.
with:
To make it a function, you could test the second parameter and return a value if
it’s 0.
-
Page 53
In the middle of the page, replace:
x ? x.first
y ? y._1
x ? x._2
with:
x -> x.first
y -> y._1
x -> x._2
(Arrows in print are displayed as question marks in ePub
-
Page 134
In Solution 5.3, second paragraph:
The cons method is recursive...
should read:
The Cons implementation is recursive...
-
Page 138
In Figure 5.6, the list2 arrow should point to the element l instead of i:
-
Page 141
Before paragraph beginning with "But forget about this optimized version...", add the following note:
Note that this code will not work as intended if the list contains NaN, since NaN * 0 = NaN.
-
Page 152
In the code example in the middle of the page, replace:
public Socket(String address,
int port,
InetAddress localAddr,
int localPort throws IOException
with:
public Socket(String address,
int port,
InetAddress localAddr,
int localPort) throws IOException
-
Page 240
Replace:
Solution 9.2
with:
Solution 9.1
-
Page 306
Last paragraph, second sentence, replace:
If it is, it calls the remove method on the
delegate.
with:
If it is, it calls the delete method on the
delegate.
-
Page 324
First paragraph and first example are to be replaced with:
In this section, you’ll implement the random number generator as simply as possible
by using a simplified version of the algorithm used in
the Java Random class:
import com.fpinjava.common.Tuple;
public class JavaRNG implements RNG {
private final long seed;
private JavaRNG(long seed) {
this.seed = seed;
}
private JavaRNG() {
this(System.currentTimeMillis());
}
private long nextSeed(long seed) {
return (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
}
@Override
public Tuple nextInt() {
return new Tuple<>((int)(seed >>> 16), new JavaRNG(nextSeed(seed)));
}
public static RNG rng(long seed) {
return new JavaRNG(seed ^ 0x5DEECE66DL & ((1L << 48) - 1));
}
public static RNG rng() {
return new JavaRNG();
}
}
The last code example is to be replaced with:
public void testInteger() {
RNG rng = JavaRNG.rng(0);
Tuple<Integer, RNG> t1 = Generator.integer(rng);
assertEquals(Integer.valueOf(384748), t1._1);
Tuple<Integer, RNG> t2 = Generator.integer(t1._2);
assertEquals(Integer.valueOf(-1155484576), t2._1);
Tuple<Integer, RNG> t3 = Generator.integer(t2._2);
assertEquals(Integer.valueOf(-723955400), t3._1);
The last paragraph is to be replaced with:
As you can see, the integer method of the Generator class is functional. You can run
this test as many times as you want; it will always produce the same values. The generator, unlike java.util.Random, has no mutable state, and the
integer method is referentially transparent.
-
Page 325
The first paragraph is to be replaced with:
If you need to produce really unpredictable numbers, you can call the
JavaRNG.rng method with a “random” long value; for example, you might use the value returned by
System.nanoTime(). Be aware, however, that the value returned doesn’t have the resolution
of 1 nanosecond, so several successive invocations might return the same value.
This can be avoided by caching the value returned by nanoTime and calling it again if
the value hasn’t changed, until a different value is obtained. The java.util.Random class offers
this service, but the code used here has been simplified. But once again, this chapter
isn’t about writing good generators, but about functionally handling state.
-
Page 395
In the second code example, replace:
assert x == 0;
with:
assert x =! 0;
-
Page 396
In the first code example, replace:
if (x != 0) throw new IllegalArgumentException("div. By 0");
with:
if (x == 0) throw new IllegalArgumentException("div. By 0");
-
Page 430
In the fourth paragraph from end of page, replace:
There are two ways to make g a total function: change the domain, making it a
function of (integer, non-null integer),
with:
There are two ways to make g a total function: change the domain, making it a
function of (integer, non-zero integer),