Changeset 38073 in project


Ignore:
Timestamp:
01/13/20 03:58:22 (10 days ago)
Author:
Kon Lovett
Message:

record instance api example uses record instance api, fix y setter

File:
1 edited

Legend:

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

    r35720 r38073  
    133133
    134134<enscript highlight=scheme>
    135 (define-record-type point (make-point x y) point?
     135(define-record-type point
     136  (make-point x y)
     137  point?
    136138  (x point-x point-x-set!)
    137139  (y point-y point-y-set!))
    138140</enscript>
    139141
    140 expands into something quite similar to:
     142expands into something similar:
    141143
    142144<enscript highlight=scheme>
    143145(begin
    144   (define (make-point x y)
    145     (make-record-instance 'point x y) )
    146   (define (point? x)
    147     (and (record-instance? x)
    148          (eq? 'point (block-ref x 0)) ) )
    149   (define (point-x p) (block-ref p 1))
    150   (define (point-x-set! p x) (block-set! p 1 x))
    151   (define (point-y p) (block-ref p 2))
    152   (define (point-y-set! p y) (block-set! p 1 y)) )
     146  (define (make-point x y)   (make-record-instance 'point x y))
     147  (define (point? x)         (record-instance? x 'point))
     148  (define (point-x p)        (record-instance-slot p 0))
     149  (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)))
    153152</enscript>
    154153
Note: See TracChangeset for help on using the changeset viewer.