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

Comments are closed.

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn 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 &…