Gauche (Gosh) Scheme modules

worker.scm

(define-module worker
    (export make-worker)
    (select-module worker) ;; separates header from function declarations

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

) ;; end module worker

main.scm

#!/usr/bin/env gosh -I.

(use worker)

(define (main argv) ;; automatically called as script
    ;; args are (cdr argv)
    (let ( (w (make-worker 0)) )
        (print "worker: " (w))
        (print "worker: " (w))
        (print "worker: " (w)) ) )

run as script

% ./main.scm