Simple exercise with keys in a map

I’m doing an exercise at exercism.io and the function and result is listed below.

I am expected to code the function below to get the result.

NucleotideCount.histogram('AATAA')

 # %{?A => 4, ?T => 1, ?C => 0, ?G => 0}

I have no idea how I can get the keys as variables with ? marks in front of them.
I discovered the Enum.fequencies and Enum.frequencies.by functions, and that is as far as I’ve been able to get, and those methods give the codepoint as keys and not the ? representation.

As a side note, is this something elixir programmers would actually do or is this just a code exercise that is slightly off the rails ?

The notation ?A is a symbolic representation of the number value for the character A. It is therefore a constant, not a variable. So:

iex> ?A == 65
true

Map keys can be any Elixir/erlang term. You will find this notation commonly used.

2 Likes