Stream: beginners

Topic: what exactly do the functions Num.bytesToU16-128 do?


view this post on Zulip James Birtles (Nov 22 2023 at 18:38):

CleanShot-2023-11-22-at-18.33.27.png

https://www.roc-lang.org/builtins/Num#bytesToU16

There's no comment explaining these and its not super clear by the name + signature what exactly these do. My assumption is they probably decode a number from the list, but firstly its unclear what the second parameter is (number of bytes that should contribute to the number maybe? seems like its an offset in the list where the number begins), and secondly if this is what this does then in what byte order?

view this post on Zulip James Birtles (Nov 22 2023 at 18:43):

CleanShot-2023-11-22-at-18.41.39.png

or I guess they actually don't do anything.. lol

view this post on Zulip Brendan Hansknecht (Nov 22 2023 at 18:48):

Not implemented in the dev backend apparently (that is what the repl uses)

view this post on Zulip Brendan Hansknecht (Nov 22 2023 at 18:54):

So all of these functions should have their api changed, they were created before the days of seamless slices.

view this post on Zulip Brendan Hansknecht (Nov 22 2023 at 18:55):

They should just take a List U8 and probably also a tag union related to endianess so [BigEndian, LittleEndian].

view this post on Zulip James Birtles (Nov 22 2023 at 18:55):

I see, that would be nice yeah!

view this post on Zulip Brendan Hansknecht (Nov 22 2023 at 18:55):

The Nat that they currently take is an offset into the list, which is unnecessary at this point.

view this post on Zulip Brendan Hansknecht (Nov 22 2023 at 18:56):

So Should probably become List U8, [BigEndian, LittleEndian] -> U64

view this post on Zulip Brian Carroll (Nov 23 2023 at 07:52):

Just to clarify: Your example code works fine in compiled programs and in the web REPL, just not in the command line REPL. The goal is for all three to eventually be equivalent, but we're not there yet.

Here's a screenshot from the web REPL
Screenshot-2023-11-23-at-07.51.41.png

view this post on Zulip James Birtles (Nov 23 2023 at 20:14):

Thanks! Good to know about trying things in the web REPL too.


Last updated: Jul 06 2025 at 12:14 UTC