[erlang-questions] Binding variables from binaries in function headers

Wes James <>
Wed Mar 9 05:26:58 CET 2011


On Tue, Mar 8, 2011 at 7:48 PM, Bernard Duggan <> wrote:
> So I've just run into an interesting little bit of behaviour that doesn't
> seem quite right.  In the following code:
> -----------------------------------------
> -module(casetest).
>
> -export([test/0]).
>
> test() ->
>    match(<<1, 2, 3, 4, 5, 6, 7, 8>>).
>
> match(<<A:1/binary, B:8/integer, _C:B/binary, _Rest/binary>>) ->
>    case A of
>        B -> wrong;
>        _ -> ok
>    end.

<snip>

I just ran it in the debugger:

c(casetest,[debug_info]).
im().
ii(casetest).
iaa([init]).

and it follows the _ -> ok branch and returns ok.

Entering the function (the debugger stops at "case A of" ) the vars are:

A is <<1>>
B is 2
_C is <<3,4>
_Rest is <<5,6,7,8>>

-wes


More information about the erlang-questions mailing list