String variable eval in binaries

Thomas Lindgren thomasl_erlang@REDACTED
Tue Jul 26 16:57:26 CEST 2005



--- Inswitch Solutions <erlang@REDACTED> wrote:

> <<[$h, $e, $l, $l, $o]>>.
> ** exited: {badarg,[{erl_eval,expr,3}]} **

You can't put a list directly into a binary. (At least
not today.)

> Str = "hello".
> <<Str>>.
> ** exited: {badarg,[{erl_eval,expr,3}]} **

Again, Str is a list. You can do

Bin1 = list_to_binary(Str).
<<Bin1/binary>>.  %% redundant in this case

Note that you can't even write <<Bin1>> directly: the
default type of Bin1 inside the binary expression is
something else, and the value of Bin1 can't be
converted to that.

So, to summarize:

1. The notation <<"foo">> suggests a list/string put
inside a binary, but this is not what it means.

2. You can't put a list directly into a binary.
Convert the list into a binary first :-) (That's more
helpful when you are mashing together several lists, I
guess.)

Best,
Thomas


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the erlang-questions mailing list