From 052a1db828aa49eac2b74d16b1eeae28bb141350 Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Wed, 9 Jul 2014 17:52:30 -0400 Subject: [PATCH 1/2] Changed deallocate/2 to only add Freq back to the list of free frequencies if it had actually appeared in Allocated. Previously, if a frequency was passed to deallocate/2 that didn't actually appear in Allocated, it would still be added into the Free list. --- code/chapter5/frequency.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/chapter5/frequency.erl b/code/chapter5/frequency.erl index 9cea6a6..c3eb5b0 100644 --- a/code/chapter5/frequency.erl +++ b/code/chapter5/frequency.erl @@ -67,4 +67,8 @@ allocate({[Freq|Free], Allocated}, Pid) -> deallocate({Free, Allocated}, Freq) -> NewAllocated=lists:keydelete(Freq, 1, Allocated), - {[Freq|Free], NewAllocated}. + case NewAllocated =:= Allocated of + true -> {Free, Allocated}; + false -> {[Freq|Free], NewAllocated} + end. + From b52fab9aea0a1417838d57b8750f6e67d29fc351 Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Thu, 10 Jul 2014 13:47:18 -0400 Subject: [PATCH 2/2] Changed syntax of case comparison. --- code/chapter5/frequency.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/chapter5/frequency.erl b/code/chapter5/frequency.erl index c3eb5b0..fc9f49b 100644 --- a/code/chapter5/frequency.erl +++ b/code/chapter5/frequency.erl @@ -67,8 +67,8 @@ allocate({[Freq|Free], Allocated}, Pid) -> deallocate({Free, Allocated}, Freq) -> NewAllocated=lists:keydelete(Freq, 1, Allocated), - case NewAllocated =:= Allocated of - true -> {Free, Allocated}; - false -> {[Freq|Free], NewAllocated} + case NewAllocated of + Allocated -> {Free, Allocated}; + _ -> {[Freq|Free], NewAllocated} end.