gleam-lang / language-tour

👩🏽‍💻 Learn Gleam in your browser
https://tour.gleam.run/
82 stars 62 forks source link

Bit arrays don't specify how specify the size with the `unit` option #57

Closed brettcannon closed 6 months ago

brettcannon commented 6 months ago

Saying io.debug(<<3:unit(2)>>) leads to the error:

rror: Invalid bit array segment
   ┌─ /src/main.gleam:10:16
   │
10 │   io.debug(<<3:unit(2)>>)
   │                ^^^^^^^ This needs an explicit size

Hint: If you specify unit() you must also specify size().
See: https://gleam.run/book/tour/bit-arrays.html

But https://tour.gleam.run/data-types/bit-arrays/ doesn't say how to specify the size as well and every guess I have made for how to do that hasn't worked.

lpil commented 6 months ago

Hello! This isn't a bug, unit isn't intended to specify size.

The linked page does say how to set the size:

Each segment of a bit array can be given options to specify the representation used for that segment.

  • size: the size of the segment in bits.
brettcannon commented 6 months ago

I do understand that "unit isn't intended to specify size", but what I don't understand is how to specify the size and unit simultaneously based on the documentation as the error message suggests; there's no example of two options being specified simultaneously.

brettcannon commented 6 months ago

FYI this was taken care of implicitly in another commit:

https://github.com/gleam-lang/language-tour/blob/f4695499a9850bdec6570b226bd8f30e5446ddc7/src/content/chapter3_data_types/lesson08_bit_arrays/en.html#L32-L33

Thanks!