Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why do lists of numbers get printed incorrectly?

0
10 Posted

Why do lists of numbers get printed incorrectly?

0

Sometimes the shell (or a program) prints a list of number in an unexpected way, for instance: 1> [65, 66, 67]. “ABC” This happens because Erlang represents strings as lists of integers, so if you ask the shell to print a list of integers, the shell takes a guess as to whether you want to see it as a list of numbers or as a string. The shell bases its guess on checking whether or not the list contains all printable characters, so you can force a string to be unprintable: 5> [0, 65, 66, 67]. [0,65,66,67] A similar problem occurs with io:fwrite(), but in that case you can take direct control by specifying the appropriate formatting character. “~s” always prints the argument as a string, “~w” always prints it as a list.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.