List
Use literals
Section titled “Use literals”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.
Examples
Section titled “Examples”| value |
|---|
| () |
| (1) |
| (1 2) |
| (1 2 3) |
| ((1) (2 2) (3 3 3)) |
Create a pair
Section titled “Create a pair”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.
Create a pair with a non-cons cdr
Section titled “Create a pair with a non-cons cdr”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.
Create a list
Section titled “Create a list”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.
Use a for-each procedure
Section titled “Use a for-each procedure”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”.
Use a for-each procedure with two lists
Section titled “Use a for-each procedure with two lists”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”.
Use a for-each procedure with three lists
Section titled “Use a for-each procedure with three lists”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”.
Use a map procedure
Section titled “Use a map procedure”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”.
Use a map procedure with two lists
Section titled “Use a map procedure with two lists”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”.
Use a map procedure with three lists
Section titled “Use a map procedure with three lists”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”.
Use a map procedure with uneven lists
Section titled “Use a map procedure with uneven lists”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”.
Use an append procedure
Section titled “Use an append procedure”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>”.
Examples
Section titled “Examples”| values | output |
|---|---|
| ’(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”.
Use a memq procedure
Section titled “Use a memq procedure”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>”.
Examples
Section titled “Examples”| value | values | output |
|---|---|---|
| 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 |
Use a memv procedure
Section titled “Use a memv procedure”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>”.
Examples
Section titled “Examples”| value | values | output |
|---|---|---|
| #\A | B | |
| #\A | #\A | A |
| #\B | #\A | B |
| #\A | #\A #\B | A |
| #\B | #\A #\B | A |
| #\C | #\A #\B | B |
| #\A | #\A #\B #\C | A |
| #\D | #\A #\B #\C | B |
Use a member procedure
Section titled “Use a member procedure”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>”.
Examples
Section titled “Examples”| value | values | output |
|---|---|---|
| ’(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 |
Get a value from an association list
Section titled “Get a value from an association list”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”.
Examples
Section titled “Examples”| 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”.
Examples
Section titled “Examples”| procedure |
|---|
| assv |
| assoc |
Check if a value is a pair
Section titled “Check if a value is a pair”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>”.
Examples
Section titled “Examples”| value | output |
|---|---|
| #f | B |
| ’() | B |
| ’(1) | A |
| ’(1 2) | A |
| (cons 1 2) | A |
Check if a value is null
Section titled “Check if a value is null”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>”.
Examples
Section titled “Examples”| value | output |
|---|---|
| #f | B |
| ’() | A |
| ’(1) | B |
| ’(1 2) | B |
| (cons 1 2) | B |
Check if a value is a list
Section titled “Check if a value is a list”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>”.
Examples
Section titled “Examples”| value | output |
|---|---|
| #f | B |
| ’() | A |
| ’(1) | A |
| ’(1 2) | A |
| (cons 1 2) | B |
Apply a cxr procedure
Section titled “Apply a cxr procedure”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”.
Examples
Section titled “Examples”| procedure | value |
|---|---|
| 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) |
Copy a list
Section titled “Copy a list”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”.
Examples
Section titled “Examples”| value |
|---|
| #f |
| ’() |
| ‘(1) |
| ‘(1 . 2) |
| ‘(1 2) |
| ‘(1 2 . 3) |
Select an element at an index
Section titled “Select an element at an index”Given a file named “main.scm” with:
(import (scheme base) (srfi 1))
(write-u8 (if (= (<procedure> '(1 2 3 4)) <value>) 65 66))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Examples
Section titled “Examples”| procedure | value |
|---|---|
| first | 1 |
| second | 2 |
| third | 3 |
| fourth | 4 |
Get the last element
Section titled “Get the last element”Given a file named “main.scm” with:
(import (scheme base) (srfi 1))
(write-u8 (if (= (last '(<values>)) <value>) 65 66))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Examples
Section titled “Examples”| values | value |
|---|---|
| 1 | 1 |
| 1 2 | 2 |
| 1 2 3 | 3 |
Get the last pair
Section titled “Get the last pair”Given a file named “main.scm” with:
(import (scheme base) (srfi 1))
(write-u8 (if (equal? (last-pair '(<values>)) '<value>) 65 66))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Examples
Section titled “Examples”| values | value |
|---|---|
| 1 | (1) |
| 1 2 | (2) |
| 1 2 3 | (3) |
| values | value |
|---|---|
| 1 2 3 . 4 | (3 . 4) |