问题
This code works:
(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)))
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".
Now, where does make-attendance-event come from?
回答1:
The identifier make-attendance-event came from a (define-struct attendance-event (...)).
A structure definition such as
(define-struct foo (a b))
will expand into multiple definitions.
- make-foo will construct foo-structures
- foo-a, foo-b field accessors
- foo? a predicate that can determine whether a value is a foo
In the Advanced language you also get:
- set-foo-a!, set-foo-b! to mutate the respective fields.
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
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.
回答2:
make-attendance-event is a function defined somewhere else in your Racket file. It's not a library function.
来源:https://stackoverflow.com/questions/31146448/where-does-a-make-function-come-from