Skip to content

Procedure

Given a file named “main.scm” with:

(import (scheme base))
(define (f x) (+ x 5))
(write-u8 (f 60))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(let ((f (lambda (x) (+ x 5))))
(write-u8 (f 60)))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (+ 60 ((lambda (x) x) 5)))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(define (f x)
((lambda () ((lambda () x)))))
(write-u8 (f 65))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(define (f) 65)
(write-u8 (f))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(define (f x) x)
(write-u8 (f 65))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(define (f x y) y)
(write-u8 (f 66 65))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(define (f x y) (+ x y))
(write-u8 (f 60 5))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(define (f x) (lambda () (set! x (+ x 1)) x))
(define g (f 64))
(write-u8 (g))
(write-u8 (g))
(write-u8 (g))

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

Given a file named “main.scm” with:

(import (scheme base))
(define (f . xs) (for-each write-u8 xs))
(f 65 66 67)

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

Use variadic arguments with a fixed argument

Section titled “Use variadic arguments with a fixed argument”

Given a file named “main.scm” with:

(import (scheme base))
(define (f x . ys) (map (lambda (z) (write-u8 (+ x z))) ys))
(f 65 0 1 2)

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

Given a file named “main.scm” with:

(import (scheme base))
(define (fibonacci x)
(if (< x 2)
x
(+
(fibonacci (- x 1))
(fibonacci (- x 2)))))
(write-u8 (+ 33 (fibonacci 10)))

When I successfully run stak main.scm

Then the stdout should contain exactly “X”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (+ 48 (apply + '(<values>))))

When I successfully run stak main.scm

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

valuesoutput
0
11
1 23
1 2 36

Call an apply procedure with a correct argument order

Section titled “Call an apply procedure with a correct argument order”

Given a file named “main.scm” with:

(import (scheme base))
(for-each write-u8 (apply 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
(65 66) (67 68) (69 70)ABCDEF

Call an apply procedure with a fixed number of arguments

Section titled “Call an apply procedure with a fixed number of arguments”

Given a file named “main.scm” with:

(import (scheme base))
(define (f x y)
(+ x y))
(write-u8 (apply f '(60 5)))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Call an apply procedure twice with the same list

Section titled “Call an apply procedure twice with the same list”

Given a file named “main.scm” with:

(import (scheme base))
(define (f x y)
(+ x y))
(define xs '(60 5))
(write-u8 (apply f xs))
(write-u8 (apply f xs))

When I successfully run stak main.scm

Then the stdout should contain exactly “AA”.

Call an apply procedure with extra arguments

Section titled “Call an apply procedure with extra arguments”

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (apply + 1 2 '(60 5)))

When I successfully run stak main.scm

Then the stdout should contain exactly “D”.

Call an apply procedure with a primitive procedure

Section titled “Call an apply procedure with a primitive procedure”

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (cdr (apply cons '(66 65))))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Call immediate procedures capturing a local variable

Section titled “Call immediate procedures capturing a local variable”

Given a file named “main.scm” with:

(import (scheme base))
(define (foo x y z)
(x)
(y)
(z))
(let ((f write-u8))
(foo
(lambda () (f 65))
(lambda () (f 66))
(lambda () (f 67))))

When I successfully run stak main.scm

Then the stdout should contain exactly “ABC”.

Given a file named “main.scm” with:

(import (scheme base))
(define (f x) x)
(f)

When I run stak main.scm

Then the exit status should not be 0.

Given a file named “main.scm” with:

(import (scheme base))
(define (f) #f)
(f #f)

When I run stak main.scm

Then the exit status should not be 0.

Do not modify environment of a reused closure with a primitive procedure

Section titled “Do not modify environment of a reused closure with a primitive procedure”

Given a file named “main.scm” with:

(import (scheme base))
(define (f x)
(cons #f (lambda () x)))
(write-u8 ((cdr (f 65))))
(write-u8 ((cdr (f 66))))
(write-u8 ((cdr (f 67))))

When I run stak main.scm

Then the stdout should contain exactly “ABC”.