The code below is basically copied from J.A.'s book:
-module(mapz).
-export([count_chars/1]).
count_chars(Str) ->
count_chars(Str, #{}).
count_chars([H|T], #{H := N}=X) -> % line that throws
count_chars(T, X#{H := N+1});
count_chars([H|T], X) ->
count_chars(T, X#{H => 1});
count_chars([], X) -> X.
however, compiling it in the shell gives me
151> c(mapz).
mapz.erl:7: variable 'H' is unbound
error
152>
I understand the importance of having H bound before it can be used for matching a key in a map; and, as far as I can tell, it is being matched to the head of the list(string) in the first argument, and is therefore bound by the time the second argument (matching against the map) is evaluated. More to the point, the example being from the book, I suspect it to be correct. The book seems to be using OTP17, however, and I'm now on 20, wonder if things have changed? But which things?
Thank you for your time.