Skip to content

Library system

Given a file named “foo.scm” with:

(define-library (foo)
(export foo)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))))

And a file named “main.scm” with:

When I successfully run stak -l foo.scm main.scm

Then the exit status should be 0.

Given a file named “foo.scm” with:

(define-library (foo)
(import (scheme base))
(begin
(write-u8 65)))

And a file named “main.scm” with:

(import (foo))
(import (foo))

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))))

And a file named “main.scm” with:

(import (foo))
(foo 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo)
(import (scheme base))
(begin
(define-syntax foo
(syntax-rules ()
((_ x)
(write-u8 x))))))

And a file named “main.scm” with:

(import (foo))
(foo 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo bar)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))
(define (bar x)
(write-u8 (+ x 1)))))

And a file named “main.scm” with:

(import (foo))
(foo 65)
(bar 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “AB”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))))

And a file named “main.scm” with:

(import (prefix (foo) bar-))
(bar-foo 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))))

And a file named “main.scm” with:

(import (only (foo) foo))
(foo 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Import only a symbol and use one of the others

Section titled “Import only a symbol and use one of the others”

Given a file named “foo.scm” with:

(define-library (foo)
(export foo bar)
(import (scheme base))
(begin
(define (foo)
#f)
(define (bar)
#f)))

And a file named “main.scm” with:

(import (only (foo) foo))
(bar)

When I run stak -l foo.scm main.scm

Then the exit status should not be 0.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo bar)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))
(define (bar x)
(write-u8 (+ x 1)))))

And a file named “main.scm” with:

(import (except (foo) foo))
(bar 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “B”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo bar)
(import (scheme base))
(begin
(define (foo)
#f)
(define (bar)
#f)))

And a file named “main.scm” with:

(import (except (foo) foo))
(foo)

When I run stak -l foo.scm main.scm

Then the exit status should not be 0.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))))

And a file named “main.scm” with:

(import (rename (foo) (foo bar)))
(bar 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo bar)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))
(define (bar x)
(write-u8 (+ x 1)))))

And a file named “main.scm” with:

(import <import set>)
(<symbol> 65)

When I successfully run stak -l foo.scm main.scm

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

import setsymboloutput
(only (prefix (foo) my-) my-foo)my-fooA
(rename (prefix (foo) my-) (my-foo my-baz))my-bazA
(except (prefix (rename (foo) (bar baz)) my-) my-foo)my-bazB

Given a file named “foo.scm” with:

(define-library (foo)
(export foo)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))))

And a file named “bar.scm” with:

(define-library (bar)
(export foo)
(import (foo)))

And a file named “main.scm” with:

(import (bar))
(foo 65)

When I successfully run stak -l foo.scm -l bar.scm main.scm

Then the stdout should contain exactly “A”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))))

And a file named “bar.scm” with:

(define-library (bar)
(export foo)
(import (only (foo) foo)))

And a file named “main.scm” with:

(import (bar))
(foo 65)

When I successfully run stak -l foo.scm -l bar.scm main.scm

Then the stdout should contain exactly “A”.

Given a file named “foo.scm” with:

(define-library (foo)
(export (rename foo bar))
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))))

And a file named “main.scm” with:

(import (foo))
(bar 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Given a file named “foo.scm” with:

(define-library (foo)
(export bar)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))
(define (bar x)
(foo x))))

And a file named “main.scm” with:

(import (scheme base) (foo))
(define (foo x)
(write-u8 66))
(foo 65)
(bar 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “BA”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo bar)
(import (scheme base))
(begin
(define (foo x)
(write-u8 x))
(define (bar x)
(foo x))))

And a file named “main.scm” with:

(import (scheme base) (foo))
(foo 65)
(bar 65)
(set! foo (lambda (x) (write-u8 66)))
(foo 65)
(bar 65)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “AABB”.

Given a file named “main.scm” with:

(import (scheme base) (scheme write))
(display 'define)

When I successfully run stak main.scm

Then the stdout should contain exactly “define”.

Given a file named “foo.scm” with:

(define-library (foo)
(export foo)
(import (scheme base))
(begin
(define foo 42)))

And a file named “main.scm” with:

(import (scheme base) (scheme write) (foo))
(display 'foo)

When I successfully run stak -l foo.scm main.scm

Then the stdout should contain exactly “foo”.