string literal in binary construction
Robert Virding
robert.virding@REDACTED
Wed Jul 26 00:46:45 CEST 2006
Whoops! Sent this from my wife's account, should be from me of course.
Robert
Elisabeth Virding wrote:
> Romain Lenglet wrote:
>
>>Claes Wikstrom wrote:
>>
>>>Romain Lenglet wrote:
>>>
>>>>Vance Shipley wrote:
>>>>
>>>>>1> <<"123">>.
>>>>>
>>>>This is syntactic sugar for <<$1, $2, $3>>.
>>>>
>>>>><<"123">>
>>>>>2> String = "123".
>>>>>"123"
>>>>>3> <<String>>.
>>>>>** exited: {badarg,[{erl_eval,expr,3}]} **
>>>>>
>>>>Use list_to_binary(String) instead.
>>>>
>>>Hmmm
>>>
>>><<A:32, String/string, B/binary>>
>>>
>>>would certainly be useful (easy to implement too)
>>>
>>
>>Or even better:
>>
>>L = [1, 2, [<<"hello">>, 3] ],
>><<A:32, L/iolist, B/binary>>
>>
> I am assuming you mean that L is an iolist and the binary should
> contain the bytes in it. I have two comments:
>
> 1. I don't really see the point as you can use list_to_binary/1 instead.
>
> 2. What would it mean in a pattern where you are matching a binary?
> Get back a binary? Or a random iolist containing he same bytes. It
> would violate a fundamental invariant which is that if use a pattern
> to build an object you can use the same pattern to pull the object
> apart and get back the same objects.
>
> The same question holds for String/string. Would using it in a match
> return a list of the bytes?
>
> Robert
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060726/f1982cc3/attachment.htm>
More information about the erlang-questions
mailing list