Skip to content

Vector

Given a file named “main.scm” with:

(import (scheme base))
(make-vector 42)

When I successfully run stak main.scm

Then the exit status should be 0.

Given a file named “main.scm” with:

(import (scheme base))
(make-vector 42 #t)

When I successfully run stak main.scm

Then the exit status should be 0.

Given a file named “main.scm” with:

(import (scheme base))
(vector-for-each write-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 (= (vector-length <value>) <length>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

valuelength
#()0
#(1)1
#(1 2)2
#(1 2 3)3
(make-vector 3)3
(make-vector 3 #t)3
(vector 1 2 3)3

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

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

vectorindexoutput
(vector 65)0A
(vector 65 66)0A
(vector 65 66)1B
(vector 65 66 67)0A
(vector 65 66 67)1B
(vector 65 66 67)2C

Given a file named “main.scm” with:

(import (scheme base))
(define xs <vector>)
(vector-set! xs <index> 88)
(vector-for-each write-u8 xs)

When I successfully run stak main.scm

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

vectorindexoutput
(vector 65)0X
(vector 65 66)0XB
(vector 65 66)1AX
(vector 65 66 67)0XBC
(vector 65 66 67)1AXC
(vector 65 66 67)2ABX

Given a file named “main.scm” with:

(import (scheme base))
(vector-for-each write-u8 (vector-append <values>))

When I successfully run stak main.scm

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

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

Given a file named “main.scm” with:

(import (scheme base))
(vector-for-each
write-u8
(vector-map + <vectors>))

When I successfully run stak main.scm

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

vectorsoutput
#(65 66 67)ABC
#(65 66 67) #(0 1 2)ACE
#(65 66 67) #(0 1 2) #(3 4)DG

Given a file named “main.scm” with:

(import (scheme base))
(vector-for-each
(lambda xs (write-u8 (apply + xs)))
<vectors>)

When I successfully run stak main.scm

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

vectorsoutput
#()
#(65)A
#(65 66)AB
#(65 66 67)ABC
#(65 66 67) #(0 1 2)ACE
#(65 66 67) #(0 1 2) #(3 4)DG

Given a file named “main.scm” with:

(import (scheme base))
(vector-for-each write-u8 (vector-copy <value>))

When I successfully run stak main.scm

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

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

Given a file named “main.scm” with:

(import (scheme base))
(define xs (vector <values>))
(vector-copy! xs <arguments>)
(for-each
(lambda (x) (write-u8 (+ x 65)))
(vector->list xs))

When I successfully run stak main.scm

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

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

Given a file named “main.scm” with:

(import (scheme base))
(define xs (vector <values>))
(vector-fill! xs <arguments>)
(for-each
(lambda (x) (write-u8 (+ x 65)))
(vector->list xs))

When I successfully run stak main.scm

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

valuesargumentsoutput
01B
0 12 0CC
0 12 1AC
0 1 23DDD
0 1 2 34 1 3AEED

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

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

Convert values between a list and a vector

Section titled “Convert values between a list and a vector”

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(define xs (iota <count>))
(write-u8 (if (equal? (vector->list (list->vector xs)) xs) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

count
0
1
2
3
4
5
6
7
8
9
16
17
32
33
64
65
128
129
512
513
4096
4097

Given a file named “main.scm” with:

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

And a file named “write.scm” with:

(import (scheme base) (scheme write) (srfi 1))
(write (list->vector (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”.

lengthindex
10
20
21
5120
5121
512510
512511
40960
40961
40964094
40964095
81920
81921
81928190
81928191