在submodule" accounts.rkt"中,我有:
#lang racket
(provide account)
(struct account (owner type amount) #:transparent)
在主模块" mainprogram.rkt"中,我有:
#lang racket
(require "accounts.rkt")
(define f (account "Jim" "Ledger" 123.45))
我点击f5并在交互区域中:
> f
(account "Jim" "Ledger" 123.45)
> (account-owner f)
account-owner undefined;
cannot reference an identifier before its definition
为什么结构getter不起作用?球拍5.3.6
答案 0 :(得分:6)
在provide
使用struct-out
,其中提供struct
定义的所有功能。
#lang racket
(provide (struct-out account))
(struct account (owner type amount) #:transparent)
这提供了account?
,account-owner
,account-type
和account-amount
(以及account
)。