Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Binary match in function head doesn't compile
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Erik Pearson  
View profile  
 More options Oct 28 2012, 2:08 pm
From: Erik Pearson <e...@defunweb.com>
Date: Sun, 28 Oct 2012 11:08:44 -0700
Local: Sun, Oct 28 2012 2:08 pm
Subject: Re: [erlang-questions] Binary match in function head doesn't compile

Is there a reference for the resolution of patterns in function/clause head
similar to

http://www.erlang.org/doc/apps/erts/match_spec.html

but for regular Erlang? The docs on the abstract format is useful

http://www.erlang.org/doc/apps/erts/absform.html

There are a few places in the docs that refer to the process of matching
the function clause head against arguments

e.g. the function overview

http://www.erlang.org/doc/reference_manual/functions.html#id74558

but it would be really useful to have those references link to
documentation which describes this process.

Thanks,
Erik.

(ps - I'm happy with your answer, Björn-Egil, but hoping this thread can
include some solid leads for others researching similar issues.)

(pps - there is a definitive response to my original post from
Björn-Egil Dahlberg
below -- he inadvertently sent it directly to me)

On Fri, Oct 26, 2012 at 11:59 AM, Björn-Egil Dahlberg <

wallentin.dahlb...@gmail.com> wrote:

> 2012/10/26 Erik Pearson <e...@defunweb.com>

>> Hi,

>> I'm wondering why this

>> test(<<Field:Len/binary, Rest/binary>>, Len) ->
>>     {Len, Field, Rest}.

>> does not compile, complaining that "variable 'Len' is unbound", while this

>> test(<<Field:2/binary, Rest/binary>>, Field) ->
>>     {Field, Rest}.

>> does. For some reason the compiler doesn't see the Len from the match
>> spec in the arguments, but it does see Field. Is that by design?

> Yes and a limitation that is being adressed.

>> BTW  supplying a variable for Len does work in this case:

>> test(Bin, Len) ->
>>   <<Field:Len/binary, Rest/binary>> = Bin,
>>    {Len, Field, Rest}.

> The difference here is that Len is bound when entering the function body
> as opposed when it is in the function head.

> We have had fierce debates on, among other things, matching behaviors for
> Maps (extended frames/hashes) which also have led to redesigning parts how
> binary matching is done in function heads. This is currently in the
> prototyping stages and it is to early to say to which release this will be
> ready.

> // Björn-Egil

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
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.