【问题标题】:Gauche unknown module data.random. What am I doing wrong?Gauche 未知模块 data.random。我究竟做错了什么?
【发布时间】:2022-11-30 03:19:40
【问题描述】:

我试图按照 Gauche 手册编写一个简单的玩具脚本,但我正在努力使用 Gauche import 机制。

这是我的脚本,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)))

但是我收到错误ERROR: unknown module data.random

据我从文档(herehere)中得知,这是 import 的正确语法,data.random 确实是模块的名称。

我还尝试定义一个 Gauche 模块,认为也许 import 只在 define-module 定义中起作用,但这并没有改变错误:

(define-module random-team-member
  (import (data.random :only (samples$))))

(select-module random-team-member)

; ... the rest of my code ...

我正在使用 Gauche 0.9.12,使用 Homebrew 安装在 MacOS (ARM64) 上。

【问题讨论】:

    标签: scheme gauche


    【解决方案1】:

    您可以使用 R7RS 样式import

    (import (only (data random) samples$))
    

    这会将 Gauche 置于 R7RS 用户模式作为副作用。要保持 Gauche 用户模式并使用其 import 样式,首先您必须 require 定义模块的文件:

    (require "data/random")
    (import (data.random :only (samples$)))
    

    但使用 use 通常更简单,它需要根据模块名称为您提供的文件:

    (use data.random :only (samples$))
    

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 1970-01-01
      • 2019-12-23
      • 2014-06-15
      • 1970-01-01
      • 2015-08-26
      相关资源
      最近更新 更多