chickadee » jiffi » struct-getter

(struct-getter ...) → proceduresyntax

Expands to an anonymous procedure that gets the value of a struct/union field.

Usage:

(struct-getter
 (ARMOR-NAME "STRUCT_NAME" PRED UNWRAP)
 FIELD-NAME
 type: FOREIGN-TYPE
 conv: G-CONV            ; optional
 name: NAME)             ; optional

NAME is an expression that evaluates to the procedure name (usually a symbol) to show in error messages if the struct cannot be unwrapped. If NAME is omitted or #f, error messages will not include a procedure name.

See define-struct-accessors for the meaning of the other macro arguments.

The procedure will behave similar to this pseudo-code:

(lambda (struct)
  (let ((ptr (UNWRAP struct NAME)))
    (if G-CONV
        (G-CONV (get-field ptr FIELD-NAME))
        (get-field ptr FIELD-NAME))))

Example:

(define event-type-getter
  (struct-getter
   (event "FOO_Event" event? unwrap-event)
   "type"
   type: int
   conv: int->event-type
   name: 'event-type-getter))