[erlang-questions] unexpected result of term_to_binary
Mon Jan 21 21:26:10 CET 2013
On Mon, Jan 21, 2013 at 8:38 PM, Steve Davis <steven.charles.davis@REDACTED
> The following appears to encode lists of integers as strings (?!?):
No no no - Erlang doesn't have strings - there are no strings in Erlang
(repeat this 100 times).
There are two internal types commonly used to represent strings
lists and binaries.
There are also string literals (ie things in programs like "aaaaabbbbb")
just shorthand for lists of integers.
term_to_binary(Term) converts Term to a Binary (Bin). You're not supposed
to know whats *in* the binary. All you need to know is that
It's like the bits in a float - you're not supposed to know what the bits
99.999999% of all programs should not know what the *internal* structure
of the thing returned by term_to_binary is (if you want to know it's the
term represented in the external format (
Just about the *only* reason to call term_to_binary is that at some later
somebody will call binary_to_term on the result.
> Eshell V5.9.3 (abort with ^G)
> 1> term_to_binary([1,2,3,4]).
> Is there a reason for this that I'm missing?
Is *not* a string - it's a binary literal
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions