子模块中的结构定义在主模块中正确提供和需要,但是getter在主模块交互区域中不起作用

Vin*_*iti 3 racket

在子模块"accounts.rkt"中,我有:

#lang racket

(provide account)

(struct account (owner type amount) #:transparent)
Run Code Online (Sandbox Code Playgroud)

在主模块"mainprogram.rkt"中,我有:

#lang racket

(require "accounts.rkt")

(define f (account "Jim" "Ledger" 123.45))
Run Code Online (Sandbox Code Playgroud)

我点击f5并在交互区域:

> f
(account "Jim" "Ledger" 123.45)
> (account-owner f)
account-owner undefined;
cannot reference an identifier before its definition
Run Code Online (Sandbox Code Playgroud)

为什么结构getter不起作用?球拍5.3.6

Gre*_*ott 6

在您的provide使用中struct-out,它提供了所定义的所有功能struct.

#lang racket

(provide (struct-out account))

(struct account (owner type amount) #:transparent)
Run Code Online (Sandbox Code Playgroud)

这提供account?,account-owner,account-type,和account-amount(以及account).