I'm new to erlang, and in erlang shell, i typed below expression:
A= <<"abc">>.
B="abc".
I want to know the differences between A
and B
, and their general usage,
Also why below expression is not correct:
C=<<abc>>.
A= <<"abc">>
is a binary. Binary is a data type in Erlang. Bit syntax encloses binary data between << and >>. In this case sequence of bits. So here the binary is 3, 8 bit values of 97,98,99 (decimal) in memory. Erlang is very powerful in handling binary data. As this is built-in, it is very efficient and there are many functions to handle binary operations.
B="abc"
is th string representation. There is no seperate data type string in Erlang. Strings in Erlang are simply lists of characters with a bit of syntactic sugar (lists as text enclosed within quotation marks).
So it is same as B=[$a,$b,$c].
Hence it is a list of integers (atleast 32 bits + pointer to next) intead of 8/16 bits per characters in other languages. Though it can handle unicode it is less effecient for large strings.
abc is an atom and that cannot be inside binary (unless converted). So C=<<abc>>.
is not correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With