Inconsistency with erlang:display/1

Am I wrong to find the output to the console of erlang:display/1 inconsistent in it’s representation of atoms representing expressions and operators?

For my current use, in debugging match specifications, I would prefer that boolean expressions were output with single quotes as all term comparisons, and some arithmetic expressions are.

1> TermComparisons = ['==', '/=', '=<', '<', '>=', '=:=', '=/+'].
['==','/=','=<','<','>=','=:=','=/+']
2> ArithmeticExpressions = ['+', '-', '*', '/', 'bnot', 'div', 'rem', 'band', 'bor', 'bxor', 'bsl', 'bsr'].
['+','-','*','/','bnot','div','rem','band','bor','bxor',
 'bsl','bsr']
3> BooleanExpressions = ['not', 'and', 'or', 'xor'].
['not','and','or','xor']
4> ShortCircuitExpressions = ['orelse', 'andalso'].
['orelse','andalso']
5> ListOperations = ['++', '--'].
['++','--']
6>  erlang:display(TermComparisons).
['==','/=','=<','<','>=','=:=','=/+']
true
7> erlang:display(ArithmeticExpressions).
['+','-','*','/',bnot,div,rem,band,bor,bxor,bsl,bsr]
true
8> erlang:display(BooleanExpressions).
[not,and,or,xor]
true
9> erlang:display(ShortCircuitExpressions).
[orelse,andalso]
true
10> erlang:display(ListOperations).
['++','--']
true
1 Like

My understanding is that erlang:display is for debugging only. For example, if you are working on the IO system, you invoke it for debugging, as the IO system may not be functioning. So it does not necessarily match the Erlang representation of terms.

1 Like

As @josevalim says, erlang:display/1 is for debugging but cannot use the regular I/O system for some reason. As you have discovered it does not quote keywords properly, I think this is a combination of not beeing needed and the fact that what is a keyword changes over time and I don’t think the VM has any knowledge of which Erlang keywords currently exists.

As another example of a term that is printed not as usual you can try an older Erlang version (for example 19) and print a large map using erlang:display.

docker run -it erlang:19
Erlang/OTP 19 [erts-8.3.5.7] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.3.5.7  (abort with ^G)
1> erlang:display(maps:from_list([{K,K} || K <- lists:seq(1,33)])). 
#<ff7d>{<4024>{[12|12],[4|4],[16|16]},<4000>{<240>{[28|28],[23|23]}},<810>{[30|30],[24|24]},<120a>{[27|27],[21|21],<9000>{[29|29],[22|22]},[31|31]},<52>{[18|18],[5|5],[14|14]},<2200>{[19|19],<4800>{[9|9],[10|10]}},[33|33],<2010>{<180>{[2|2],[6|6]},[3|3]},<600>{[32|32],[1|1]},<8082>{[7|7],[8|8],[13|13]},[25|25],<805>{[17|17],[20|20],[15|15]},[26|26],[11|11]}
true
1 Like