<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 20, 2019 at 2:44 PM Valentin Micic <<a href="mailto:v@micic.co.za">v@micic.co.za</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div><div><br></div><div>Oh, please, don’t get me wrong, I like the ability to write <font face="Courier New"><<World:2, Group:2, User:2, <b>_:2</b>>> = <<SomeFlags>></font>.</div><div>However, with this construct, you could still extract your flags, but this would not require any new data type (such as bitstring) —  e.g. <font face="Courier New">is_binary(<<World:2, Group:2, User:2, <b>_:2</b>>> = </font><span style="font-family:"Courier New""> <<SomeFlags>></span><font face="Courier New">) </font> will merrily report true.</div><div><br></div><div>Contrast this with <font face="Courier New"><<World:2, Group:2, User:2>> = Some6BitBitstring;</font></div><div><br></div><div>which, In order to work, must have <span style="font-family:"Courier New"">Some6BitBitstring</span> set to exactly a six-bit Bitstring, which could only be set from within Erlang runtime, thus fairly artificial construct with respect to the environment, e.g. OS, socket, files, etc.</div><div><br></div><div>Thus, my assertion is that bitstring is a pretty pointless data type. There.</div></div></div></blockquote><div><br></div><div>Well, let's take a TCP packet header for example; if you follow the current wikipedia definition with experimental RFCs, there are 3 reserved bits, followed by all the flags, set on 9 bits. You could either need to pattern match all the flags individually, but you can also write, thanks to Erlang and bitstrings, a function that accepts a pattern like <<..., _Reserved:3, Flags:9/bits, ...>> and then ask decode_flags(Flags) to return you a list of atoms for all the values that are set.</div><div><br></div><div>This might actually be desirable because some flags change meaning according to other flags; the ECE flag's value can be triple depending on whether it is 0, or whether it is 1 and the current value of the SYN flag being set (1 or 0). <br></div><div><br></div><div>You can obviously work around this, but if you do it C-style, you're likely to have to gobble the reserved bits along with the flags, and then extract the experimental flag from the reserved bits, and carry it as an extra value somewhere.</div><div><br></div><div>Mostly, there's interesting stuff that you can do with bitstrings that are matched-out sections of 8-bit aligned binaries, regardless of where you are reading them from and what the initial machine alignment was.<br></div><div><br></div></div></div>