[erlang-questions] Binaries and "strings"
Robert Virding
rvirding@REDACTED
Fri Feb 26 23:42:49 CET 2010
On 26 February 2010 23:33, Steve Davis <steven.charles.davis@REDACTED> wrote:
> Found this binary behavior interesting:
>
> 1> <<"one", "two">>.
> <<"onetwo">>
This creates a binary containing the characters (bytes) of the two string.
> 2> <<"one" "two">>.
> <<"onetwo">>
Here the two string are concatenated to one already in the parser, so
you are actually writing <<"abcdef">>. This is feature is useful as it
allows you to split a long string into many sub strings without extra
computational cost.
You can also write "abc" ++ "def" in code and the compiler will
optimise away the ++. It can always do this if the first argument to
++ is a list literal.
Robert
More information about the erlang-questions
mailing list