Chez Scheme modules

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 (print . args)
    (for-each display args)
    (newline) )

(define (main argv)
    (let ( (w (make-worker 0)) )
        (print "worker: " (w))
        (print "worker: " (w))
        (print "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 )
(generate-wpo-files )
(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

One thought on “Chez Scheme modules”

Comments are closed.

Mentions

  • Scheme - Mark writes