The Erlang shell "guesses" whether a given list is a printable string and prints it that way for convenience. Can this "convenience" be disabled?
相关问题
- Is “new” in Erlang part of the official standard a
- how to create a keep-alive process in Erlang
- ejabberd and Erlang installation with lager_transf
- Encrypt (cryptojs) - Decrypt (erlang)
- How to use erlang-examples
相关文章
- How do I modify a record in erlang?
- Check active timers in Erlang
- undefined function maps:to_json/1
- How to convert datetime() to timestamp() in Erlang
- what good orm api will work well with scala or erl
- GC performance in Erlang
- When to “let it crash” and when to defend the code
- Intercept login/logout ejabberd
I don't think you can prevent it. Prepending an atom seems like a kludge - it does alter your original string.
I typically use lists:flatten(String) to force it to a string - especially the returnvalue of io_lib:format() does not always print as a string. Using lists:flatten() on it makes it one.
I use the following "C-style":
You can disable such behavior with
shell:strings/1
function starting with Erlang R16B.Just remember that this is option global to all node shells, and it might be wise to set it back after finishing playing is shell in longer living nodes.
No, there is no way to disable it. The best alternative I find is to either explicitly print out the value in the query (with
io:format
) or after the fact do:io:format("~w\n", [v(-1)])
.I tend to do it by prepending an atom to my list in the shell.
for example:
could also be [a,65,66,67], of course. but [a|fun_that_returns_a_list()] will print "the right thing(ish) most of the time"
I don't know if it's possible to change the default behavior of the shell, but you can at least format your output correctly, using io:format.
Here is an example:
And since the shell is only for experimenting / maintenance,
io:format()
should be at least enough for your real application. Maybe you should also consider to write your own format/print method, e.g.formatPerson()
or something like that, which formats everything nicely.As of Erlang/OTP R16B, you can use the function shell:strings/1 to turn this on or off. Note that it also affects printing of things that are actually meant to be strings, such as
"foo"
in the following example: