Skip to content

Library system

Define a library

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 scheme -l foo.scm main.scm

Then the exit status should be 0.

Import a library twice

Given a file named “foo.scm” with:

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

And a file named “main.scm” with:

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

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

Then the stdout should contain exactly “A”.

Import a procedure

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 scheme -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Import a macro

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 scheme -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Import procedures

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 scheme -l foo.scm main.scm

Then the stdout should contain exactly “AB”.

Import a procedure with a prefix

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 scheme -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Import only a symbol

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 scheme -l foo.scm main.scm

Then the stdout should contain exactly “A”.

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 scheme -l foo.scm main.scm

Then the exit status should not be 0.

Import symbols except one

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 scheme -l foo.scm main.scm

Then the stdout should contain exactly “B”.

Import symbols except one and use it

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 scheme -l foo.scm main.scm

Then the exit status should not be 0.

Import a renamed procedure

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 scheme -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Nest import qualifiers

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 scheme -l foo.scm main.scm

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

Examples

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

Re-export an imported procedure

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 scheme -l foo.scm -l bar.scm main.scm

Then the stdout should contain exactly “A”.

Re-export a qualified imported procedure

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 scheme -l foo.scm -l bar.scm main.scm

Then the stdout should contain exactly “A”.

Export a renamed procedure

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 scheme -l foo.scm main.scm

Then the stdout should contain exactly “A”.

Do not modify a library environment

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) (scheme write) (foo))
(define (foo x)
(write-u8 66))
(foo 65)
(bar 65)

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

Then the stdout should contain exactly “BA”.

Modify a library environment

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) (scheme write) (foo))
(foo 65)
(bar 65)
(set! foo (lambda (x) (write-u8 66)))
(foo 65)
(bar 65)

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

Then the stdout should contain exactly “AABB”.