Where does a make- function come from?

泪湿孤枕 提交于 2019-12-23 15:51:38

问题


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.

  1. make-foo will construct foo-structures
  2. foo-a, foo-b field accessors
  3. foo? a predicate that can determine whether a value is a foo

In the Advanced language you also get:

  1. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!