Why is there no dynamic bit pattern in the function argument?

I am experimenting with bit pattern matching in Erlang:

-module(test).
-export([test/2]).

%test(P,<<X:P,0:1>>) ->
%    X.

test(P,X) ->
    <<Y:P,0:1>> = X,
    Y.

when compiling a commented version, test/2I get a complaint that the "variable" P is "unbound". Is there a good reason not to let the first version work the same as the second?

+3
source share
2 answers

Because in the commented version of P, the length - for Erlang to work, must double match - combine the value of the second parameter with an undefined pattern ...

, , " " - " ", , ...

X , , <<Y:P,0:1>> don't match X, !

+4

, . .

, P , . , P .

0

Source: https://habr.com/ru/post/1706635/


All Articles