Course of Raku / Advanced / More about built-in types / Native types 🆕 / Exercises / A native array

Solution: A native array

Here is a possible solution to the task.

Code

my uint8 @bytes = 100, 200, 255;
say @bytes.sum;

🦋 You can find the source code in the file native-array.raku.

Output

555

Comments

  1. Putting the sized native type uint8 before the @ array declares an array where every element is stored as a single unsigned byte — the compact layout that suits binary data.

  2. The wrap-around limit applies to each element (0..255), not to the result of summing them. .sum boxes the total into an ordinary Int, so 100 + 200 + 255 gives the full 555.

Course navigation

A native array   |   Strings