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

2 thoughts on “Gambit 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

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

  • mdhughes
  • Mark writes