-
|
In Java I would write |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Lisette supports Go slices, but not (yet) Go arrays. The difference is that a slice in Go (and Lisette) is dynamically sized, while an array is fixed (it can't be resized). Your code example is actually a slice, but preallocated; the runtime preallocates 1024 bytes for it. Lisette also does not (yet) support preallocating slices. The simplest way to create a byte-slice is simply manually giving it a type (as a plain number defaults to // byte is an alias for uint8, so both of these are equivalent, and can hold values from 0 to 255
let buffer: Slice<byte> = [0, 255]
let buffer: Slice<uint8> = [0, 255]
// alternatively
let mut c = Slice.new<byte>()
c = c.append(1)
// or even
let mut c = Slice.new() // Type is Slice<T>
c = c.append(1 as byte) // After this its cast to Slice<byte>@ivov Maybe a |
Beta Was this translation helpful? Give feedback.
Lisette supports Go slices, but not (yet) Go arrays. The difference is that a slice in Go (and Lisette) is dynamically sized, while an array is fixed (it can't be resized).
Your code example is actually a slice, but preallocated; the runtime preallocates 1024 bytes for it. Lisette also does not (yet) support preallocating slices.
The simplest way to create a byte-slice is simply manually giving it a type (as a plain number defaults to
int):