Skip to content

SRFI 1

Map a function on a list and append elements

Section titled “Map a function on a list and append elements”

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8
(if (equal?
(append-map (lambda (x) (list (* 2 x) (* x x))) '(<input>))
'(<output>))
65
66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

inputoutput
12 1
1 22 1 4 4
1 2 32 1 4 4 6 9

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (delete-duplicates '(<input>)) '(<output>)) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

inputoutput
11
1 11
1 1 2 21 2
1 2 1 21 2
1 2 1 3 3 2 31 2 3

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (filter odd? '(<input>)) '(<output>)) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

inputoutput
11
2
1 21
1 2 31 3
1 2 3 41 3
1 2 3 4 5 61 3 5

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (fold + 0 '(<elements>)) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

elementsoutput
0
11
1 23
1 2 36

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (fold-right + 0 '(<elements>)) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

elementsoutput
0
11
1 23
1 2 36

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (iota <arguments>) '(<elements>)) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

argumentselements
0
10
20 1
30 1 2
1 11
1 22
3 55 6 7
3 5 25 7 9

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (eq? (find even? '(<elements>)) <element>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

elementselement
#f
1#f
1 3#f
22
1 22
1 3 4 54

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (find-tail even? '(<elements>)) <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

elementsvalue
#f
1#f
1 3#f
2’(2)
1 2’(2)
1 3 4 5’(4 5)

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (any even? '(<elements>)) <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

elementsvalue
#f
1#f
1 3#f
2#t
1 2#t
1 2 3 4 5#t

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (every even? '(<elements>)) <value>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

elementsvalue
#t
1#f
1 3#f
2#t
1 2#f
2 4 6#t
2 4 5#f
1 2 3 4 5#f

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (list-index <predicate> <lists>) <index>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

predicatelistsindex
even?’()#f
even?’(1)#f
even?’(1 3)#f
even?’(2)0
even?’(1 2)1
even?’(1 2 3)1
even?’(1 3 2)2
=‘(0 2) ‘(1 2 3)1
=‘(2 1 3) ‘(1 2 3)2

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (reduce + 42 '(<elements>)) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

elementsoutput
42
00
11
1 23
1 2 36

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (equal? (reduce-right + 42 '(<elements>)) <output>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

elementsoutput
42
00
11
1 23
1 2 36

Given a file named “main.scm” with:

(import (scheme base) (srfi 1))
(write-u8 (if (eq? (cddddr '(x x x x)) '()) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.