Skip to content

Vector

Make a vector

Given a file named “main.scm” with:

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

When I successfully run scheme main.scm

Then the exit status should be 0.

Make a vector with a fill value

Given a file named “main.scm” with:

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

When I successfully run scheme main.scm

Then the exit status should be 0.

Convert a vector to a list

Given a file named “main.scm” with:

(import (scheme base))
(for-each write-u8 (vector->list #(65 66 67)))

When I successfully run scheme main.scm

Then the stdout should contain exactly “ABC”.

Get a length of a vector

Given a file named “main.scm” with:

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

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

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

Get an element in a vector

Given a file named “main.scm” with:

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

When I successfully run scheme main.scm

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

Examples

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

Set an element in a vector

Given a file named “main.scm” with:

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

When I successfully run scheme main.scm

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

Examples

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