Skip to content

List

Given a file named “main.scm” with:

(import (scheme base))
(define x '<value>)

When I successfully run stak main.scm

Then the exit status should be 0.

value
()
(1)
(1 2)
(1 2 3)
((1) (2 2) (3 3 3))

Given a file named “main.scm” with:

(import (scheme base))
(cons 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))
(cons 1 2)

When I successfully run stak main.scm

Then the exit status should be 0.

Given a file named “main.scm” with:

(import (scheme base))
(list 1 2 3)

When I successfully run stak main.scm

Then the exit status should be 0.

Given a file named “main.scm” with:

(import (scheme base))
(for-each
(lambda (x) (write-u8 (+ 60 x)))
'(5 6 7))

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

Given a file named “main.scm” with:

(import (scheme base))
(for-each
(lambda (x y) (write-u8 (+ x y)))
'(65 66 67)
'(1 2 3))

When I successfully run stak main.scm

Then the stdout should contain exactly “BDF”.

Given a file named “main.scm” with:

(import (scheme base))
(for-each
(lambda (x y z) (write-u8 (+ x y z)))
'(65 66 67)
'(1 2 3)
'(4 5 6))

When I successfully run stak main.scm

Then the stdout should contain exactly “FIL”.

Given a file named “main.scm” with:

(import (scheme base))
(for-each
write-u8
(map
(lambda (x) (+ 60 x))
'(5 6 7)))

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

Given a file named “main.scm” with:

(import (scheme base))
(for-each
write-u8
(map
(lambda (x y) (+ x y))
'(65 66 67)
'(1 2 3)))

When I successfully run stak main.scm

Then the stdout should contain exactly “BDF”.

Given a file named “main.scm” with:

(import (scheme base))
(for-each
write-u8
(map
(lambda (x y z) (+ x y z))
'(65 66 67)
'(1 2 3)
'(4 5 6)))

When I successfully run stak main.scm

Then the stdout should contain exactly “FIL”.

Given a file named “main.scm” with:

(import (scheme base))
(for-each
write-u8
(map
(lambda (x y) (+ x y))
'(65 66 67 68)
'(1 2 3)))

When I successfully run stak main.scm

Then the stdout should contain exactly “BDF”.

Given a file named “main.scm” with:

(import (scheme base))
(for-each write-u8 (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)ABCD

Share the last argument in an append procedure

Section titled “Share the last argument in an append procedure”

Given a file named “main.scm” with:

(import (scheme base))
(define x (list 65))
(define y (append '(65) x))
(for-each write-u8 y)
(set-car! x 66)
(for-each write-u8 y)

When I successfully run stak main.scm

Then the stdout should contain exactly “AAAB”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (memq <value> '(<values>)) 65 66))

When I successfully run stak main.scm

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

valuevaluesoutput
1B
11A
21B
11 2A
21 2A
31 2B
11 2 3A
41 2 3B

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (memv <value> '(<values>)) 65 66))

When I successfully run stak main.scm

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

valuevaluesoutput
#\AB
#\A#\AA
#\B#\AB
#\A#\A #\BA
#\B#\A #\BA
#\C#\A #\BB
#\A#\A #\B #\CA
#\D#\A #\B #\CB

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (member <value> '(<values>)) 65 66))

When I successfully run stak main.scm

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

valuevaluesoutput
’(1)B
’(1)(1)A
’(2)(1)B
’(1)(1) (2)A
’(2)(1) (2)A
’(3)(1) (2)B
’(1)(1) (2) (3)A
’(4)(1) (2) (3)B

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (cdr (<procedure> 42 '((1 . 1) (42 . 65) (3 . 3)))))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

procedure
assq
assv
assoc

Get a value from an association list of characters

Section titled “Get a value from an association list of characters”

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (cdr (<procedure> #\B '((#\A . 1) (#\B . 65) (#\C . 3)))))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

procedure
assv
assoc

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (pair? <value>) 65 66))

When I successfully run stak main.scm

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

valueoutput
#fB
’()B
’(1)A
’(1 2)A
(cons 1 2)A

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (null? <value>) 65 66))

When I successfully run stak main.scm

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

valueoutput
#fB
’()A
’(1)B
’(1 2)B
(cons 1 2)B

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (list? <value>) 65 66))

When I successfully run stak main.scm

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

valueoutput
#fB
’()A
’(1)A
’(1 2)A
(cons 1 2)B

Given a file named “main.scm” with:

(import (scheme base) (scheme cxr))
(write-u8 (<procedure> '<value>))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

procedurevalue
car(65)
cdr(66 . 65)
caar((65))
cadr(66 65)
cdar((66 . 65))
cddr(66 66 . 65)
caaar(((65)))
caadr(66 (65))
cadar((66 . (65)))
caddr(66 66 65)
cdaar(((66 . 65)))
cdadr(66 (66 . 65))
cddar((66 66 . 65))
cdddr(66 66 66 . 65)
cadddr(66 66 66 65)

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (equal? (list-copy <value>) <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

value
#f
’()
‘(1)
‘(1 . 2)
‘(1 2)
‘(1 2 . 3)