Changeset 35846 in project


Ignore:
Timestamp:
07/12/18 08:52:33 (4 days ago)
Author:
snoewchen
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/datatypes

    r35845 r35846  
    181181  (reader Point))
    182182
    183 ; outdated - use simple-cells instead
    184 (use cells)
     183(use simple-cells)
    185184
    186185;; Base object
     
    188187
    189188;; Couple objects
     189(define-object-type
     190  COUPLE couple? make-couple (
     191    (parent obj?)
     192    (cell-1 cell?)
     193    (cell-2 cell?))
     194  (override)
     195  ((First) (cell-1))
     196  ((Second) (cell-2))
     197  ((First-set! (value number?)) (cell-1 value))
     198  ((Second-set! (value number?)) (cell-2 value)))
     199
    190200(define cpl
    191201  (make-couple obj (cell 1) (cell 2)))
    192 (couple? cpl)
    193 (object? cpl)
    194 (not (couple? First))
     202(couple? cpl) ; -> #t
     203(object? cpl) ; -> #t
     204(not (couple? First)) ; -> #t
    195205(cpl (Types))
    196 (cpl (Info))
    197 (cpl (Invariant))
     206(cpl (Info)) ; -> ((Types) ... (First) ... (First-set! (value number?)) ...
     207(cpl (Invariant)) ; -> (and (parent (Invariant)) (cell-1 cell?) ...
    198208(cpl (Ancestors))
    199 (= (cpl (First)) 1)
    200 (= (cpl (Second)) 2)
    201 (cpl (First-set! 10))
    202 (cpl (Second-set! 20))
    203 (= (cpl (First)) 10)
    204 (= (cpl (Second)) 20)
    205    
     209(= (cpl (First)) 1) ; -> #t
     210(= (cpl (Second)) 2) ; -> #t
     211(cpl (First-set! 10)) ; -> 1 (= old value of cell-1)
     212(cpl (Second-set! 20)) ; -> 2 (= old value of cell-2)
     213(= (cpl (First)) 10) ; -> #t
     214(= (cpl (Second)) 20) ; -> #t
     215
    206216;; Triple objects
     217(define-object-type
     218  TRIPLE triple? make-triple (
     219    (parent couple?)
     220    (cell-3 cell?))
     221  (override)
     222  ((Third) (cell-3))
     223  ((Third-set! (value number?)) (cell-3 value)))
     224
    207225(define trp (make-triple cpl (cell 3)))
    208226(trp (Ancestors))
    209 (trp (Info))
    210 (= (trp (Third)) 3)
    211 (trp (Third-set! 30))
    212 (= (trp (Third)) 30)
    213 (= (trp (First)) 20)
    214 (= (trp (Second)) 20)
    215 (trp (Second-set! 2))
    216 (= (trp (Second)) 2)
    217 (trp (First-set! 25))
    218 (= (trp (First)) 100)
    219 (triple? trp)
    220 (not (triple? cpl))
    221 (couple? trp)
    222 (object? trp)
     227(trp (Info)) ; -> ((Types) ... (First) ... (Third) (Third-set! (value number?)))
     228(= (trp (Third)) 3) ; -> #t
     229(trp (Third-set! 30)) ; -> 3 (= old value of cell-3)
     230(= (trp (Third)) 30) ; -> #t
     231(= (trp (First)) 20) ; -> #f
     232(= (trp (Second)) 20) ; -> #t
     233(trp (Second-set! 2)) ; -> 20 (= old value of cell-2)
     234(= (trp (Second)) 2) ; -> #t
     235(trp (First-set! 25)) ; -> 10 (= old value of cell-1)
     236(= (trp (First)) 100) ; -> #f
     237(triple? trp) ; -> #t
     238(not (triple? cpl)) ; -> #t
     239(couple? trp) ; -> #t
     240(object? trp) ; -> #t
    223241
    224242;; Note that Messages are precondition-checked and constructors pass the
Note: See TracChangeset for help on using the changeset viewer.