I'm working on this exercism problem and trying to pull 7 bits out of a bitstring, attach a leading / marker bit at the start of the byte and append both to the start of another accumulator bitstring.
In the process, I've stumbled on a confusing error, that unhelpfully is just called ArgumentError, if I try to specify the size of something that's already a bitstring.
Here's an example:
iex(28)> a = <<64::size(7)>>
<<64::size(7)>>
iex(29)> b = <<1::size(1)>>
<<1::size(1)>>
iex(30)> <<b::size(1), a::size(7)>>
** (ArgumentError) argument error while evaluating iex at line 30
(stdlib 4.0) eval_bits.erl:143: :eval_bits.eval_exp_field/6
(stdlib 4.0) eval_bits.erl:77: :eval_bits.create_binary/2
(stdlib 4.0) eval_bits.erl:68: :eval_bits.expr_grp/5
(stdlib 4.0) erl_eval.erl:543: :erl_eval.expr/6
(iex 1.13.4) lib/iex/evaluator.ex:310: IEx.Evaluator.handle_eval/3
iex(30> # of course, this works
iex(30)> <<b::bitstring, a::bitstring>>
<<192>>
why can't I specify a size for a bitstring? It seems like that could be useful for catching unexpected sizes.
And why is the error message so unhelpful?