Reputation: 13893
I am attempting to follow the Gauche manual to write a simple toy script, but I am struggling with the Gauche import
mechanism.
Here is my script, random-team-member
:
#!/usr/bin/env gosh
(import (data.random :only (samples$)))
(define team-members
(list "billy"
"nilly"
"silly"
"willy"))
(define (generator->first gen)
(car (generator->list gen 1)))
(define (sample1 items)
(generator->first (samples$ items)))
(define (main args)
(print (sample1 team-members)))
But I get the error ERROR: unknown module data.random
.
As far as I could tell from the docs (here and here), this is the correct syntax for import
, and data.random
is indeed the name of the module.
I also tried defining a Gauche module, thinking that maybe import
only worked inside a define-module
definition, but that didn't change the error:
(define-module random-team-member
(import (data.random :only (samples$))))
(select-module random-team-member)
; ... the rest of my code ...
I am using Gauche 0.9.12, installed on MacOS (ARM64) using Homebrew.
Upvotes: 0
Views: 60
Reputation: 52529
You can use R7RS style import
:
(import (only (data random) samples$))
which puts Gauche into R7RS user mode as a side-effect. To remain in Gauche user mode and use its style of import
, first you have to require
the file that defines the module:
(require "data/random")
(import (data.random :only (samples$)))
but it's often simpler to use use
, which requires the file for you based on the module name:
(use data.random :only (samples$))
Upvotes: 1