<div dir="ltr">Hi,<div><br></div><div>I'm trying to compile the count_characters example from Programming Erlang book.</div><div>But I get an error, and I can't see a typo.</div><div><br></div><div><div>-module(t).</div><div>-export([count_characters/1]).</div><div><br></div><div>count_characters(Str) -></div><div>   count_characters(Str, #{}).</div><div><br></div><div>count_characters([H|T], #{ H := N }=X) -></div><div>   count_characters(T, X#{ H := N+1 });</div><div><br></div><div>count_characters([H|T], X) -></div><div>   count_characters(T, X#{ H => 1 });</div><div><br></div><div>count_characters([], X) -></div><div>        X.</div></div><div><br></div><div><div>1> c(t).</div><div>t.erl:7: variable 'H' is unbound</div><div>error</div><div>2> </div></div><div><br></div><div>This behavior contradicts the point made in the text:</div><div><br></div><div>        There are two things to note about count_characters/2.</div><div>        In the first clause, the variable H inside the map is also<br></div><div>        defined outside the map and thus is bound (as required).<br></div><div>        In the second clause, we use map_extend to add a new<br></div><div>        key to the map.<br></div><div><br></div><div>Thanks!</div><div><br></div><div>Mark</div></div>