<div dir="ltr">I live in a world of pain wherein I receive 4K binary blob packets with a tightly packed schema that changes every few weeks.<div><br></div><div>One way to handle it is, e.g., (field names changed to anonymize the guilty):</div>
<div><br></div><div>-define(PACKET, <<Version:8, Flavor:3, Moisture:5, IsDelicious:1, [...], IsFattening:1 >>).</div><div><br></div><div>(and then, in my state machine...)</div><div><br></div><div>s_connected(P = ?PACKET) -></div>
<div> io:format("Moisture: ~p~n", [Moisture]), %% twitch</div><div>[...]</div><div><br></div><div>and conversely</div><div><br></div><div>mold_together_a_packet(Version, Flavor, Moisture, IsDelicious, ...) -></div>
<div> ?PACKET.</div><div><br></div><div>or if I wanted to put some modicum of discipline on that thing maybe something like:</div><div><br></div><div>-define(OUTGOINGPACKET, [Version, Flavor, Moisture, IsDelicious, ...]).</div>
<div><br></div><div>mod_together_a_packet(?OUTGOINGPACKET) -></div><div> ?PACKET.</div><div><br></div><div>both of these things seem iffy and super messed up because I have to define each field separately each in two different macros, and also the namespace pollution is bad. Maybe I'm doing it wrong, but those seem to me like the best of a set of bad ways to do it. Yet, it seems like the language knows enough to be *able* to bind a bitstring comprehension directly to a record, and probably will know enough soon to bind it directly to a map. </div>
<div><br></div><div>e.g., </div><div><br></div><div><<M#Version:8, M#{ Flavor }:3, M#{ Moisture }:5, M#{ IsDelicious }:1, M#{ Color }#{ Red }:8, M#{ Color }#{ Blue } :8, M#{ Color }#{ Green }:8, M#{ IsFattening } :1 >> = P</div>
<div><br></div><div>and also</div><div><br></div><div><<M#Version:8, M#{ Flavor }:3, M#{ Moisture }:5, BitDepth:8, M#{ Color }#{ Red }:BitDepth, M#{ Color }#{ Blue } :BitDepth, M#{ Color }#{ Green }:BitDepth, M#{ IsFattening } :1 >> = P<br>
</div><div><br></div><div>and also the science fictional:</div><div><br></div><div>SchemaType = #{ Version: 8, Flavor: 3, Moisture: 5, ... }, %% assumes insert ordering on maps instead of term ordering because I prefer it that way</div>
<div><<M = SchemaType>> = P,</div><div>M#{ Flavor } = 5,</div><div><<SchemaType = M>>.</div><div><br></div><div>disclaimer: not a programming language theorist.</div><div><br></div><div>anyway, it would be super great if something like this were to exist; or, if there's something better than the nasty macro magic I ended up using that is a second place finisher in the absence of this, I'd love to know what it is.</div>
<div><br></div><div>F.</div></div>