Created
April 22, 2019 23:28
-
-
Save jrfondren/6afb3050343cf1915ebf17ec3b59454c to your computer and use it in GitHub Desktop.
distinct seq[byte]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
Seq32 = distinct seq[byte] | |
proc `[]=`(arr: var Seq32; i: int; x: byte) = | |
var s: seq[byte] = cast[seq[byte]](arr) | |
s[i] = x | |
proc firsthalf*(arr: var array[64, byte]): Seq32 = | |
Seq32(arr[0..31]) | |
proc mutatehalf*(arr: var Seq32) = | |
for i in 0 .. 31: | |
arr[i] = byte(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import seq32 | |
var buf: array[64, byte] | |
var x = firsthalf(buf) | |
x.mutatehalf | |
echo buf # no mutation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment