[erlang-questions] binary elements greater than 255
Valentin Micic
valentin@REDACTED
Sat Apr 26 08:40:02 CEST 2008
Well... is it only shell? Say I write a function like:
F=fun(A) -> <<0, A>> end.
and then do:
> F( 10 ).
> <<0, 10>>
...
> F(100).
> <<0, 100>>
...
> F(1000).
> <<0, 232>>
...
> F(10000000).
> <<0, 128>>
...
> F(1111111111).
> <<0, 199>>
I've been under impression that functional objects are implicitly compiled,
therefore behave like any ERLANG program, thus, should generate exception
for, say, F(1000). I suppose, one should not assume anything, eh?
V.
PS
This does not seem to be a new thing, as I can trace the same behaviour back
to R9C.
----- Original Message -----
From: "Peter Lund" <erlang@REDACTED>
To: "Igor Ribeiro Sucupira" <igorrs@REDACTED>
Cc: <erlang-questions@REDACTED>; "Zvi" <exta7@REDACTED>
Sent: Saturday, April 26, 2008 7:04 AM
Subject: Re: [erlang-questions] binary elements greater than 255
> Please observe that this is just how the shell works...
>
> In any erlang program you make, you would use the list_to_binary/1
> function.
>
> Eshell V5.3 (abort with ^G)
> 1> <<0,1111111111>>.
> <<0,199>>
> 2> list_to_binary([0,1111111111]).
>
> =ERROR REPORT==== 26-Apr-2008::07:02:13 ===
> Error in process <0.24.0> with exit value:
> {badarg,[{erlang,list_to_binary,[[0,16#423A35C7]]},{erl_eval,do_apply1,5},{shell,eval_loop,2}]}
>
> ** exited: {badarg,[{erlang,list_to_binary,[[0,1111111111]]},
> {erl_eval,do_apply1,5},
> {shell,eval_loop,2}]} **
>
> And here you get a proper crash
>
> With correct indata you get good output.
>
> 3> list_to_binary([0,111,255]).
> <<0,111,255>>
>
> /Peter
>
>
> Igor Ribeiro Sucupira skrev:
>> I think this is the classic situation "If you do it wrong, the
>> behaviour is undefined". :-)
>> (On the case at hand, it looks it's just taking the least significant
>> byte from the number)
>>
>> In fact, maybe it should raise a warning when compiling a module with
>> this kind of code... (?)
>>
>> On Fri, Apr 25, 2008 at 10:01 PM, Zvi <exta7@REDACTED> wrote:
>>
>>> Hi Igor,
>>>
>>> I know that lately computer industry decided to switch from 6-bit to
>>> 8-bit
>>> bytes :), which when unsigned can hold values in range 0..255. But this
>>> wasn't my question. I asked, why Erlang compiler didn't return error,
>>> when
>>> you give it input like <<256>>. I think it's a bug.
>>>
>>> Zvi
>>>
>>>
>>> Igor Ribeiro Sucupira wrote:
>>> >
>>> > No.
>>> > If you use integers in a binary, each must be in the range [0, 255]
>>> > (1-byte).
>>> >
>>> > Igor.
>>> >
>>> > On Fri, Apr 25, 2008 at 7:44 PM, Zvi <exta7@REDACTED> wrote:
>>> >>
>>> >> Is this a bug?
>>> >> Zvi
>>> >> ------------------------------------------------------------
>>> >> Erlang (BEAM) emulator version 5.6 [smp:2] [async-threads:0]
>>> >>
>>> >> Eshell V5.6 (abort with ^G)
>>> >> 1>
>>> >> 1> <<0,255>>.
>>> >> <<0,255>>
>>> >> 2> <<0,256>>.
>>> >> <<0,0>>
>>> >> 3> <<0,257>>.
>>> >> <<0,1>>
>>> >> 4> <<0,65536>>.
>>> >> <<0,0>>
>>> >> 5> <<0,1111111111>>.
>>> >> <<0,199>>
>>> >> 6>
>>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list