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