Skip to content

Bytevector

Given a file named “main.scm” with:

(import (scheme base))
(write-bytevector #u8(65 66 67))

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (bytevector-length <value>) <length>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

valuelength
#u8()0
#u8(0)1
#u8(0 0)2
#u8(0 0 0)3

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (bytevector-u8-ref <vector> <index>))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

vectorindex
#u8(65)0
#u8(65 66)0
#u8(66 65)1
#u8(65 66 66)0
#u8(66 65 66)1
#u8(66 66 65)2

Given a file named “main.scm” with:

(import (scheme base))
(define xs (bytevector <values>))
(bytevector-u8-set! xs <index> <value>)
(write-u8 (if (equal? xs #u8(<result>)) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

valuesindexvalueresult
0011
0 1022 1
0 1120 2
0 1 2033 1 2
0 1 2130 3 2
0 1 2230 1 3

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(define xs (bytevector-append <values>))
(for-each
(lambda (index)
(write-u8 (bytevector-u8-ref xs index)))
(iota (bytevector-length xs)))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

valuesoutput
#u8()
#u8() #u8()
#u8(65)A
#u8(65) #u8(66)AB
#u8(65) #u8(66) #u8(67)ABC
#u8(65) #u8(66 67) #u8(68 69 70)ABCDEF

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(define xs (bytevector-copy <value>))
(for-each
(lambda (index)
(write-u8 (bytevector-u8-ref xs index)))
(iota (bytevector-length xs)))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

valueoutput
#u8()
#u8(65)A
#u8(65 66)AB
#u8(65 66 67)ABC

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(define xs (bytevector <values>))
(bytevector-copy! xs <arguments>)
(for-each
(lambda (index)
(write-u8 (+ 65 (bytevector-u8-ref xs index))))
(iota (bytevector-length xs)))

When I successfully run stak main.scm

Then the stdout should contain exactly “<output>”.

valuesargumentsoutput
0 #u8()
0 1 20 #u8(3 4 5)DEF
0 1 21 #u8(3 4)ADE
0 1 22 #u8(3)ABD
0 1 2 3 41 #u8(5 6 7)AFGHE
0 1 2 31 #u8(4 5 6 7) 1AFGH
0 1 2 31 #u8(4 5 6 7) 1 3AFGD

Given a file named “main.scm” with:

(import (scheme base) (scheme write))
(write (bytevector-u8-ref (make-bytevector <length> 42) <index>))

When I successfully run stak main.scm

Then the stdout should contain exactly “42”.

lengthindex
10
20
21
30
31
32
80
81
86
87
90
91
97
98
6463
6564
512511
513512
40964095
40974096

Given a file named “main.scm” with:

(import (scheme base) (scheme write))
(define xs (include "./value.scm"))
(write (bytevector-u8-ref xs <index>))

And a file named “write.scm” with:

(import (scheme base) (scheme write) (srfi 1))
(write
(apply
bytevector
(map
(lambda (x) (remainder x 256))
(iota <length>))))

And I run the following script:

Terminal window
stak write.scm > value.scm

When I successfully run stak main.scm

Then the stdout should contain exactly “<index>”.

lengthindex
10
20
21
5120
5121
512254
512255
40960
40961
4096254
4096255
81920
81921
8192254
8192255