Chibi Scheme modules

worker.sld

(define-library (worker)
    (export make-worker)
    (import (scheme base))
    (include "worker.scm")
) ;; end library worker

worker.scm

(define (make-worker n)
    (lambda ()  (set! n (+ n 1))  n) )

main.scm

#!/usr/bin/env chibi-scheme

(import (scheme base)
    (scheme write)
    (scheme process-context)
    (worker)
)

(define (print . args)
    (for-each display args)
    (newline) )

(define (main argv)
    (print argv)
    (let ( (w (make-worker 0)) )
        (print "worker: " (w))
        (print "worker: " (w))
        (print "worker: " (w)) ) )

(main (cdr (command-line))) ;; or remove this line, add -r to shebang line

run as script

% ./main.scm