Changeset 38074 in project


Ignore:
Timestamp:
01/13/20 05:06:28 (9 months ago)
Author:
Kon Lovett
Message:

api example, encourage SRFI 17

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/man/5/Module (chicken memory representation)

    r38073 r38074  
    124124=== Record instance
    125125
    126 
    127 ==== make-record-instance
    128 
    129 <procedure>(make-record-instance SYMBOL ARG1 ...)</procedure>
    130 
    131 Returns a new instance of the record type {{SYMBOL}}, with its
    132 slots initialized to {{ARG1 ...}}.  To illustrate:
     126As illustration, the SRFI 9 definition:
    133127
    134128<enscript highlight=scheme>
     
    140134</enscript>
    141135
    142 expands into something similar:
     136could expand into:
    143137
    144138<enscript highlight=scheme>
    145139(begin
     140  (import (chicken base))
     141  (import (chicken memory representation))
    146142  (define (make-point x y)   (make-record-instance 'point x y))
    147143  (define (point? x)         (record-instance? x 'point))
    148   (define (point-x p)        (record-instance-slot p 0))
    149144  (define (point-x-set! p x) (record-instance-slot-set! p 0 x))
    150   (define (point-y p)        (record-instance-slot p 1))
    151   (define (point-y-set! p y) (record-instance-slot-set! p 1 y)))
    152 </enscript>
     145  (define point-x            (getter-with-setter (cut record-instance-slot <> 0) point-x-set!))
     146  (define (point-y-set! p y) (record-instance-slot-set! p 1 y))
     147  (define point-y            (getter-with-setter (cut record-instance-slot <> 1) point-y-set!)))
     148</enscript>
     149
     150
     151==== make-record-instance
     152
     153<procedure>(make-record-instance SYMBOL ARG1 ...)</procedure>
     154
     155Returns a new instance of the record type {{SYMBOL}}, with its
     156slots initialized to {{ARG1 ...}}.
    153157
    154158
Note: See TracChangeset for help on using the changeset viewer.