Skip to content

if

Use if expressions

Given a file named “main.scm” with:

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

When I successfully run scheme main.scm

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

Examples

valueoutput
#fB
#tA

Use nested if expressions

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 <expression>)

When I successfully run scheme main.scm

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

Examples

expressionoutput
(if #t (if #t 65 67) 67)A
(if #f 67 (if #f 67 66))B

Use deeply nested if expressions

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 <expression>)

When I successfully run scheme main.scm

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

Examples

expressionoutput
(if #t (if #t (if #t 65 67) 67) 67)A
(if #f 67 (if #f 67 (if #f 67 66)))B

Use a one-sided if expression

Given a file named “main.scm” with:

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

When I successfully run scheme main.scm

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

Examples

valueoutput
#f
#tA

Use sequenced if expressions

Given a file named “main.scm” with:

(import (scheme base))
(if <value1>
(write-u8 65)
(write-u8 66))
(if <value2>
(write-u8 65)
(write-u8 66))
(if <value3>
(write-u8 65)
(write-u8 66))

When I successfully run scheme main.scm

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

Examples

value1value2value3output
#t#t#tAAA
#t#t#fAAB
#t#f#tABA
#t#f#fABB
#f#t#tBAA
#f#t#fBAB
#f#f#tBBA
#f#f#fBBB

Use deeply nested if expressions

Given a file named “main.scm” with:

(import (scheme base))
(if <value1>
(begin
(write-u8 65)
(if <value2>
(begin
(write-u8 65)
(if <value3>
(write-u8 65)
(write-u8 66)))
(begin
(write-u8 66)
(if <value3>
(write-u8 65)
(write-u8 66)))))
(begin
(write-u8 66)
(if <value2>
(begin
(write-u8 65)
(if <value3>
(write-u8 65)
(write-u8 66)))
(begin
(write-u8 66)
(if <value3>
(write-u8 65)
(write-u8 66))))))

When I successfully run scheme main.scm

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

Examples

value1value2value3output
#t#t#tAAA
#t#t#fAAB
#t#f#tABA
#t#f#fABB
#f#t#tBAA
#f#t#fBAB
#f#f#tBBA
#f#f#fBBB

Use sequenced if expressions in a nested if expression

Given a file named “main.scm” with:

(import (scheme base))
(if <value1>
(begin
(write-u8 65)
(if <value2>
(write-u8 65)
(write-u8 66))
(if <value3>
(write-u8 65)
(write-u8 66)))
(begin
(write-u8 66)
(if <value2>
(write-u8 65)
(write-u8 66))
(if <value3>
(write-u8 65)
(write-u8 66))))

When I successfully run scheme main.scm

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

Examples

value1value2value3output
#t#t#tAAA
#t#t#fAAB
#t#f#tABA
#t#f#fABB
#f#t#tBAA
#f#t#fBAB
#f#f#tBBA
#f#f#fBBB