[erlang-questions] String versus variable in binary literal

Ivan Uemlianin ivan@REDACTED
Wed May 16 11:00:28 CEST 2012


On 16/05/2012 09:49, Michel Rijnders wrote:
> Hi,
>
> Confused newbie here. Can someone please explain the following:
>
> 1>  <<"foo">>.
> <<"foo">>
> 2>  Foo = "foo".
> "foo"
> 3>  <<Foo>>.
> ** exception error: bad argument
>
> What's the error in the last case?
>
> Best,
> Michel

You can use list_to_binary/1 for the same effect:

1> <<"foo">>.
<<"foo">>
2> Foo = "foo".
"foo"
3> list_to_binary(Foo).
<<"foo">>

Ivan


-- 
============================================================
Ivan A. Uemlianin PhD
Llaisdy
Speech Technology Research and Development

                     ivan@REDACTED
                      www.llaisdy.com
                          llaisdy.wordpress.com
               github.com/llaisdy
                      www.linkedin.com/in/ivanuemlianin

               "hilaritas excessum habere nequit"
                  (Spinoza, Ethica, IV, XLII)
============================================================



More information about the erlang-questions mailing list