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 (lambda (x) (+ x 65)) #(0 1 2)))

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

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