Gambit Scheme modules

worker.sld

(define-library (worker)
    (import (scheme base))
    (export
        make-worker
    )
    (begin

(include "./worker.scm")

)) ;; define-library worker

worker.scm

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

main.scm

#!/usr/bin/env -S gsi-script -:search=.

(import (gambit)
    (worker)
)

;;(main) with variable args is magically called by gsi-script & compiler
(define (main . argv)
    (println "argv: " argv)
    (let ( (w (make-worker 0)) )
        (println "worker: " (w))
        (println "worker: " (w))
        (println "worker: " (w)) )
)

run as script

% ./main.scm 666
argv: 666
worker: 1
worker: 2
worker: 3

build.zsh

#!/bin/zsh
export GAMBOPT=search=.
gsc -o main -exe . worker.sld main.scm

(make sure to import each of the sld library definitions, NOT the scm library impl!)

compile

% ./build.zsh
worker.sld:
.../worker.c:
main.scm:
.../main.c:
.../main_.c:
% ./main 666
argv: 666
worker: 1
worker: 2
worker: 3

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