生成函数从何而来?
Where does a make- function come from?
此代码有效:
(define list-of-events
(for/list ([(date code)
(in-query odc "select date, code from attendance
where student_id = ? and term_code = ?"
"12345" "654321")])
(make-attendance-event date code)))
但是,当我尝试复制另一个 table 的行为时,与 make-attendance-event 并行的项目抱怨它是 "unbound identifier"。
现在,make-attendance-event 从何而来?
make-attendance-event 是在您的 Racket 文件中其他地方定义的函数。它不是库函数。
标识符 make-attendance-event
来自 (define-struct attendance-event (...))
。
结构定义如
(define-struct foo (a b))
将扩展为多个定义。
- make-foo 将构造 foo-structures
- foo-a, foo-b 字段访问器
- 富?可以确定值是否为 foo
的谓词
在高级语言中您还可以获得:
- set-foo-a!, set-foo-b!改变相应的字段。
请注意,您可以将鼠标悬停在 DrRacket 中的标识符 make-attendance-event
上,右键单击并选择 "Jump to Binding Occurrence" 以查看定义标识符的位置。
此代码有效:
(define list-of-events
(for/list ([(date code)
(in-query odc "select date, code from attendance
where student_id = ? and term_code = ?"
"12345" "654321")])
(make-attendance-event date code)))
但是,当我尝试复制另一个 table 的行为时,与 make-attendance-event 并行的项目抱怨它是 "unbound identifier"。
现在,make-attendance-event 从何而来?
make-attendance-event 是在您的 Racket 文件中其他地方定义的函数。它不是库函数。
标识符 make-attendance-event
来自 (define-struct attendance-event (...))
。
结构定义如
(define-struct foo (a b))
将扩展为多个定义。
- make-foo 将构造 foo-structures
- foo-a, foo-b 字段访问器
- 富?可以确定值是否为 foo 的谓词
在高级语言中您还可以获得:
- set-foo-a!, set-foo-b!改变相应的字段。
请注意,您可以将鼠标悬停在 DrRacket 中的标识符 make-attendance-event
上,右键单击并选择 "Jump to Binding Occurrence" 以查看定义标识符的位置。