Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does a make- function come from?

Tags:

racket

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?

like image 598
bentaisan Avatar asked Dec 05 '25 05:12

bentaisan


1 Answers

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.

like image 61
soegaard Avatar answered Dec 09 '25 06:12

soegaard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!