Skip to content

Library system

Given I run the following script:

Terminal window
cp $STAK_ROOT/prelude.scm .

And the exit status should 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:

When I run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

Then the exit status should be 0.

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm bar.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm bar.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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 run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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

When I run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

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

When I run the following script:

Terminal window
cat prelude.scm foo.scm main.scm | stak-compile > main.bc
stak-interpret main.bc

Then the stdout should contain exactly “AABB”.