[erlang-patches] Bit string generators, unsized binaries, modules and the REPL

Fredrik <>
Tue Apr 2 11:07:42 CEST 2013


On 03/31/2013 04:22 PM, Anthony Ramine wrote:
> Hello,
>
> People on IRC noticed a difference between compiled modules and the REPL in how some binary generators are handled.
>
> Compare:
>
> $ cat unsized_bin_gen_pat.erl
> -module(unsized_bin_gen_pat).
> -export([t/0]).
> t() ->  <<  <<X,Tail/binary>>  ||<<X,Tail/binary>>  <=<<1,2,3>>  >>.
> $ erlc unsized_bin_gen_pat.erl
> $ erl
>
> 1>  % compiled
> 1>  unsized_bin_gen_pat:t().
> <<1,2,3,2,3,3>>
> 2>  % evaluated
> 2>  <<  <<X,Tail/binary>>  ||<<X,Tail/binary>>  <=<<1,2,3>>  >>.
> <<1,2,3>>
>
> I don't think the compiler should be changed to behave like the REPL, nor I think the REPL should be changed to behave like the compiler. Instead, I think an unsized binary tail in the pattern of a binary generator does not make sense, and this should happen:
>
> $ erlc unsized_bin_gen_pat.erl
> unsized_bin_gen_pat.erl:3: binary fields without size are not allowed in patterns of bit string generators
>
> This patch implements this new error and simplifies how v3_core works with forbidden unsized tail segments in patterns of bit string generators.
>
> 	git fetch https://github.com/nox/otp illegal-bitstring-gen-pattern
>
> 	https://github.com/nox/otp/compare/erlang:maint...illegal-bitstring-gen-pattern
> 	https://github.com/nox/otp/compare/erlang:maint...illegal-bitstring-gen-pattern.patch
>
> Looking at the commit 5daa001 by Björn Gustavsson "Don't generate multiple tail segments in binary matching", this patch will probably by rejected as it seems the compiler behaves as wanted by the OTP team. If this is indeed the case, erl_eval should be fixed.
>
> Regards,
>
Hello,
I've fetched your branch and it is currently in the 'pu' branch.
Thanks,

-- 

BR Fredrik Gustafsson
Erlang OTP Team



More information about the erlang-patches mailing list