Re: bitstring library

5 views
Skip to first unread message

Richard Jones

unread,
Dec 3, 2008, 3:22:08 PM12/3/08
to Abdallah Saffidine, bits...@googlegroups.com
On Tue, Dec 02, 2008 at 11:43:07PM +0100, Abdallah Saffidine wrote:
> Hello,
>
> I would like to use bitstring to represent compactly boolean data, and then
> perform matching against them. Ideally I would like to write something like:
>
> bitmatch bstring with
> |{ 00000 } ->
> |{ 11111 } ->
> |{ 1___0 } ->
> |{ 0_100 } ->
> | _ -> "default case"
>
> Is it possible with bitstring library ? If not is it likely to be offered
> one day ? Or am I completely mistaken and my problem has nothing to do with
> bitstrings ? (in which case you might have some idea of a workaround...)

Yes, this is possible. The syntax currently is slightly different,
ie. you have to write something like this:

bitmatch bstring with
| { 0 : 1; 0 : 1; 0 : 1; 0 : 1; 0 : 1 } -> (* the 00000 case *)
| (* etc *)

or:

bitmatch bstring with
| { 0b00000 : 5 } -> (* the 00000 case *)
| { 0b11111 : 5 } -> (* the 11111 case *)
| { 1 : 1; _ : 1; _ : 1; _ : 1; 0 : 1 } -> (* the 1____0 case *)
| (* etc *)

That third case could also be written as:

| { 1 : 1; _ : 3; 0 : 1 } -> ...

A more compact syntax might be invented for bitstrings like this, but
I'm not sure what would be a good syntax here.

Rich.

--
Richard Jones
Red Hat

Reply all
Reply to author
Forward
0 new messages