[erlang-questions] bit syntax: what does "<<1234>> =" match?

Loïc Hoguin essen@REDACTED
Sat Feb 26 18:21:18 CET 2011


On 02/26/2011 06:04 PM, Anthony Ramine wrote:
> Le 26 févr. 2011 à 17:37, Anton Lebedevich a écrit :
>
>> On 02/26/2011 05:24 PM, Anthony Ramine wrote:
>>
>> Yes,<<1234>>  on the right side becomes<<210>>, but I can't figure out
>> what happens with<<1234>  on the left side. Obviously it isn't truncated
>> to<<210>>  (least significant 8 bits), it doesn't fit into 16 bit too:
>> 1>  <<1234>>  =<<1234:16>>.
>> ** exception error: no match of right hand side value<<4,210>>
>>
>> Regards,
>> Anton Lebedevich.
>
> As I said, the thing on the left is a pattern, so I think it actually compiles to
> "a binary which the only byte's value is 1234", which obviously won't ever match
> anything.
>
> That could be the intended behaviour as much as it could be a bug, IMHO.

What about this:

9> <<1234:8>> = <<1234:8>>.
** exception error: no match of right hand side value <<"Ò">>
10> <<1234:16>> = <<1234:16>>.
<<4,210>>

-- 
Loïc Hoguin
Dev:Extend



More information about the erlang-questions mailing list