
patrickdm
Genetic Algorithms in Elixir: Ch4. errata in evolve function (page 59)
At the beginning of page 59, in chapter 4
alter the evolve function to track a generation parameter, like this:
def evolve(problem, generation, opts \\ []) do
# ...
if terminate?(population, generation) do
# ...
else
generation = generation + 1
...
|> evolve(population, generation opts)
end
end
The evolve
definition is missing the first param population
;
a comma is also missing between the last two params of the evolve call, at the end of the function’s body,
Edit: I guess problem
should be in the params of the recursive call to evolve
in place of population
, and as prefix in the terminate?
call.
We have also to include an initial value for generation
in run/2
’s evolve call, to avoid an>
(ArithmeticError) bad argument in arithmetic expression
due to an uninitialized generation in the + 1 operation. (I’m starting from generation 0)
Corrige:
def run(problem, opts \\ []) do
population = initialize(&problem.genotype/0, opts)
first_generation = 0
population
|> evolve(problem, first_generation, opts)
end
def evolve(population, problem, generation, opts \\ []) do
# ...
if problem.terminate?(population, generation) do
# ...
else
generation = generation + 1
...
|> evolve(problem, generation, opts)
end
end
(Hope I’m not bothering anyone with this small corrections, I’m really enjoying the book)
Most Liked

seanmor5
Thank you for finding all these things . I’m glad you’re enjoying the book! I’ll go back and fix this one as well.

patrickdm
It is a pleasure to be helpful, I’m just reading the book, studying the concepts and putting the code at work, so the small glitches in the redaction wake up the little debugger-daemon in me… They actually help me to focus and understand the overall logic and goals! Also I know how hard is to spot them when you know every and each word of your book by memory. I’m glad to be of some help, while learning so much!
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /zig
- /scala
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /c
- /julia
- /slackware
- /neovim