worker.ss
(library (worker)
(export make-worker)
(import (chezscheme))
(define (make-worker n)
(lambda () (set! n (+ n 1)) n) )
) ;; end library worker
main.ss
#!/usr/bin/env scheme-script
(import (chezscheme)
(worker))
(define (println . args)
(for-each display args)
(newline) )
(define (main argv)
(println "argv: " argv)
(let ( (w (make-worker 0)) )
(println "worker: " (w))
(println "worker: " (w))
(println "worker: " (w)) ) )
(main (command-line-arguments))
build.sh
#!/bin/sh
if [[ $# -ne 1 ]]; then
echo "Usage: build.sh MAINNAME"
exit 1
fi
rm -f *.so *.wpo
mkdir -p bin
cat <<ENDTEXT |scheme -q --optimize-level 3
(compile-imported-libraries #t)
(generate-wpo-files #t)
(compile-program "$1.ss")
(compile-whole-program "$1.wpo" "bin/$1")
ENDTEXT
rm -f *.so *.wpo
if [[ -f "bin/$1" ]]; then
chmod 755 "bin/$1"
fi
run as script
% ./main.ss
build & run as binary
% ./build.sh main
% bin/main