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 (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

One thought on “Chez Scheme modules”

  1. My Scheme Stuff: Category: Scheme: My blog posts on Scheme. scheme-test-unit: My unit test runner for SRFI-64. Basic Games in Scheme: Classic BASIC games &…

Comments are closed.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)

Mentions

  • My Scheme Stuff: Category: Scheme: My blog posts on Scheme. scheme-test-unit: My unit test runner for SRFI-64. Basic Games in Scheme: Classic BASIC games &…

Mentions

  • Mark writes