Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brettcannon opened this issue Mar 14, 2024 · 3 comments
Closed

Comments

@brettcannon
Copy link
Contributor

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
Copy link
Member

lpil commented Mar 15, 2024

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.

@lpil lpil closed this as not planned Won't fix, can't repro, duplicate, stale Mar 15, 2024
@brettcannon
Copy link
Contributor Author

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
Copy link
Contributor Author

FYI this was taken care of implicitly in another commit:

Multiple options can be given to a segment by separating each with a dash:
<code>x:unsigned-little-size(2)</code>.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants