Skip to content

Array helpers?

Reverse

let reversed : 128 * u8
    [@I] = my_big_array[127 - I] // By hand
let reversed : 128 * u8
    [@I] = my_big_array[-1 - I %] // Automod
let reversed = new reverse(my_big_array) // Standard component?

---

component reverse[T, N : Int]

    i_data : N * T
    o_data : N * T

o_data[@I] = i_data[N - 1 - I]
let reversed = my_big_array.reversed // method-like in array type?

---

type ...

def reversed : ...
    [@I] = ...[N - 1 - I]
let reversed : 128 * u8
    [@I] = my_big_array[reversed.Len - 1 - I] // Access attribute?

Last

component last[T, N : Int]
    (i_data) = o_data

    i_data = N * T
    o_data = T

o_data = i_data[N - 1]

---

component reversed[T, N : Int]
    (i_data) = o_data

    i_data = N * T
    o_data = N * T

o_data[@I] = i_data[N - 1]

---

// This syntax does not exist and likely won't exist, it is just draft notes.
type [][T, N : Int]

Require N >= 0

Match N
    0 -> ()
    * -> type [0 : N - 1] * T

---

// We could add "common" functions to arrays
type [][T, A : Int, B : Int]

.first = self[A]
.last = self[B]
.reversed = self[B:A]
.Len = Abs(B - A) + 1
.Left = A
.Right = B
Edited by come_744
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information