[erlang-questions] Binary Matching Restrictions

Björn Gustavsson <>
Thu May 6 08:13:23 CEST 2010


On Wed, May 5, 2010 at 11:03 PM, alisdair sullivan
<> wrote:
> I misspoke, I meant specifically in the case of a recursive function. My question is why the optimization is not applied in the following case (some clauses omited):
>
> f(<<S:1/binary, Rest/binary>>) ->
>     ...
>     g(Rest, ...).
>
> g(Rest, ...) ->
>     ...
>     f(Rest).
>
> The documentation of the beam_bsm.erl module indicates the optimization should be applied in this case but bin_opt_info shows it is not.

beam_bsm mostly only analyzes code within a single
function, thought the comments do not explicitly say
so.

To get your code optimized, you will need to move
the code for the g function into the f/1 function.
Alternately, the following should also also work:

f(<<S:1/binary, Rest/binary>>) ->
    ...
    g(...),
    f(Rest).

g(...) ->
    ...

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list