I believe you can use closure instead of case to achieve re-usability of binary context.
parse(Len, Bin) ->
On Oct 31, 2012, at 9:52 PM, Erik Pearson wrote:
> Thanks, Robert, that helps clarify the state of things._______________________________________________
> Do you think it would be useful if it worked "the way I would like"?
> It seems that in the specific case of walking a binary by extending
> the length of a sub-binary in the match (via a Len argument) would be
> much more efficient than binary accumulation which always does at
> least some allocation (256 bytes) and copying, and also more efficient
> than moving the code into a case (where the Len will already be
> bound.) It seems that the compiler would need to notice that what it
> thinks is an unbound variable is actually guaranteed to be bound in
> another argument, and express this as a dependency in the head pattern
> match code.
> On Wed, Oct 31, 2012 at 11:45 AM, Robert Virding
>> It is different when match *INSIDE* a binary. There, by necessity, the
>> <<N,B1:N/binary,Rest/binary>> = Bin
>> From: "Erik Pearson" <e...@defunweb.com>
>> Is there a reference for the resolution of patterns in function/clause head
>> but for regular Erlang? The docs on the abstract format is useful
>> There are a few places in the docs that refer to the process of matching the
>> e.g. the function overview
>> but it would be really useful to have those references link to documentation
>> (ps - I'm happy with your answer, Björn-Egil, but hoping this thread can
>> (pps - there is a definitive response to my original post from Björn-Egil
>> On Fri, Oct 26, 2012 at 11:59 AM, Björn-Egil Dahlberg
>>> 2012/10/26 Erik Pearson <e...@defunweb.com>
>>>> I'm wondering why this
>>>> test(<<Field:Len/binary, Rest/binary>>, Len) ->
>>>> does not compile, complaining that "variable 'Len' is unbound", while
>>>> test(<<Field:2/binary, Rest/binary>>, Field) ->
>>>> does. For some reason the compiler doesn't see the Len from the match
>>> Yes and a limitation that is being adressed.
>>>> BTW supplying a variable for Len does work in this case:
>>>> test(Bin, Len) ->
>>> The difference here is that Len is bound when entering the function body
>>> We have had fierce debates on, among other things, matching behaviors for
>>> // Björn-Egil
erlang-questions mailing list
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.