Making the Most of Bit Arrays
18 points by crowdhailer
18 points by crowdhailer
(sorry if this is off-topic)
"serif, variable-width code blocks certainly is a choice" actually I'm not sure it was a choice. The CSS contains:
code { font-family: 'Liberation Mono'; }
but that font isn't loaded. I think the font should be loaded (either self-hosted or from a CDN), and the CSS should instead be:
code { font-family: 'Liberation Mono', monospace; }
anyways good article, Gleam does have some really neat features huh
Very interesting language feature! Binary pattern matching like this really came like a fresh breeze when in many other languages you can only decode imperatively, or via obscure DSLs like Python's struct.unpack(">bhl"). I also found Erlang's documentation on its bit syntax a good read.
The article mentions that bit arrays are "built in to the BEAM virtual machine". But since Gleam transpiles into Erlang source code, I do wonder whether bit arrays are supported via the Erlang compiler frontend (i.e., "syntax sugar") or if BEAM has special instructions/bytecodes for pattern matching (i.e., VM support). The latter case would be interesting since it seems to me in many languages pattern matching is pure syntax sugar.
just like list comprehensions, are binary comprehension also an option ? erlang does support it, fwiw.
also, just a humble suggestion: an example using this to parse ipv4 header, udp header etc. would be so much better.
Interestingly enough, Common Lisp has bit vectors as a required type of specialised vector in the language.