make 函数从何而来? [英] 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)))
但是,当我尝试复制另一个表的行为时,make-attendance-event 的并行项会抱怨它是未绑定的标识符".
However, when I try to duplicate the behavior for another table, the parallel item to make-attendance-event complains about it being an "unbound identifier".
现在,make-attendance-event 从何而来?
Now, where does make-attendance-event come from?
推荐答案
标识符 make-attendance-event
来自一个 (define-struct duty-event (...))代码>.
The identifier make-attendance-event
came from a (define-struct attendance-event (...))
.
结构定义如
(define-struct foo (a b))
将扩展为多个定义.
- make-foo 将构建 foo 结构
- foo-a、foo-b 字段访问器
- foo?一个可以判断一个值是否为 foo 的谓词
在高级语言中,您还可以获得:
In the Advanced language you also get:
- set-foo-a!, set-foo-b!改变相应的字段.
See more here: http://docs.racket-lang.org/htdp-langs/advanced.html?q=define-struct#%28form._%28%28lib._lang%2Fhtdp-advanced..rkt%29._define-struct%29%29
请注意,您可以将鼠标悬停在 DrRacket 中的标识符 make-attendance-event
上,右键单击并选择跳转到绑定事件"以查看标识符的定义位置.
Note that you can hover over the identifier make-attendance-event
in DrRacket, right click and choose "Jump to Binding Occurrence" to see where an identifier is defined.
这篇关于make 函数从何而来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!