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”.

value length
#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”.

vector index
#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”.

values index value result
0 0 1 1
0 1 0 2 2 1
0 1 1 2 0 2
0 1 2 0 3 3 1 2
0 1 2 1 3 0 3 2
0 1 2 2 3 0 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>”.

values output
#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>”.

value output
#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>”.

values arguments output
0 #u8()
0 1 2 0 #u8(3 4 5) DEF
0 1 2 1 #u8(3 4) ADE
0 1 2 2 #u8(3) ABD
0 1 2 3 4 1 #u8(5 6 7) AFGHE
0 1 2 3 1 #u8(4 5 6 7) 1 AFGH
0 1 2 3 1 #u8(4 5 6 7) 1 3 AFGD

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

length index
1 0
2 0
2 1
3 0
3 1
3 2
8 0
8 1
8 6
8 7
9 0
9 1
9 7
9 8
64 63
65 64
512 511
513 512
4096 4095
4097 4096

Given a file named “main.scm” with:

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

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 “A”.

length index
1 0
2 0
2 1
512 0
512 1
512 254
512 255
4096 0
4096 1
4096 254
4096 255
8192 0
8192 1
8192 254
8192 255