I have a function where I enter from the erlang shell:
huffman:table([$H,$E,$L,$L,$O]).
I want to keep the ASCII values like that, but mine are changed into integers in the output. How do I make the program not interpret them into integers?
As $H
is just another way of writing the integer 72, there is no way to print it as $H
built-in to Erlang. You'd have to write your own function to output the values this way.
In the example you show, it looks like you need to keep small integers as integers, while printing alphabetic values as letters. Something like this might work:
maybe_char_to_string(N) when $A =< N, N =< $Z ->
[$$, N];
maybe_char_to_string(N) ->
integer_to_list(N).
This is what it outputs:
3> foo:maybe_char_to_string($H).
"$H"
4> foo:maybe_char_to_string(1).
"1"