Changeset 28231 in project for wiki/eggref/4/tuples


Ignore:
Timestamp:
02/01/13 14:30:25 (8 years ago)
Author:
juergen
Message:

tuples-1.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/tuples

    r27163 r28231  
    44== tuples
    55
    6 Tuples are a datatype which has much in common with vectors. Namely they store a finite number of items with random access and make them available via (tuple-ref tup n). But contrary to vectors, the items can only by accessed but not assigned to. If you want to change a particular item, you must package it into a box or a single, which is a special tuple storing exactly one item, which can be changed via single-set! without changing the identity of the single object itself.
    7 
    8 singles are the only tuples, which can assign to their content. Other special tuples are empty, couple and triple. Note, that couples can be used instead of pairs to implement immutable lists.
     6Tuples are a datatype which has much in common with vectors. Namely they
     7store a finite number of items with random access and make them
     8available via (tuple-ref tup n). But contrary to vectors, the items can
     9only by accessed but not assigned to. If you want to change a particular
     10item, you must package it into a box or a single, which is a special
     11tuple storing exactly one item, which can be changed via single-set!
     12without changing the identity of the single object itself.
     13
     14singles are the only tuples, which can assign to their content. Other
     15special tuples are couple and triple. They are all packaged in their
     16own modules, and all of them use another module, raw-tuples, which
     17contains the basic implementations without any checks.
     18
     19Note, that couples can be used instead of pairs to
     20implement immutable lists.
    921
    1022== Documentation
    1123
    12 In this implementation skiplists are implemented in the Design by
    13 Contract style, i.e. using the contracts module. A corollary of this is,
    14 that the documentation is included in one of the two modules in form of
    15 a procedure with the module's name. Apart from this documentation
    16 procedure the two modules, %tuples and tuples, have the same
    17 interface.  The first module contains the raw implementations of the
    18 procedures, the second imports the first with prefix % and wraps those
    19 prefixed routines with contracts.
    20 
    21 ==== tuples
    22 
    23 <procedure>(tuples [sym])</procedure>
    24 
    25 returns all available routines of the module when called without an
    26 argument, but when called with one of these routines as a symbol,
    27 returns its contract and documentation string.
    28 
    29 Another way to get the complete documentation is to use print-doclist from the contracts module. Issuing
    30 
    31 <enscript highlight=scheme>
    32   (import tuples (only contracts print-doclist))
    33   (with-output-to-file "tuples.docu" (lambda () (print-doclist)))
    34 </enscript>
    35 
    36 you'll get a file tuples.docu which is the basis for the following
    37 documentation.
     24In this implementation tuples and their relatives (except raw-tuples)
     25are implemented in the Design by Contract style, i.e. using the dbc egg.
     26A corollary of this is, that the documentation is included in each of
     27these modules in form of a procedure with the module's name. Called
     28without any argument, the list of exported symbols is shown, with such a
     29symbol as argument, the symbol's documentation is shown, and with a string
     30argument, some wiki-like documentation is printed to a file, which you
     31can inspect below.
     32
     33=== module tuples
     34
     35==== list->tuple
     36
     37<procedure>(list->tuple lst)</procedure>
     38
     39function (result)
     40
     41<enscript highlight=scheme>
     42
     43(list->tuple lst)
     44  (list? lst)
     45  (and (%tuple? result) (= (length lst) (%tuple-length result)))
     46
     47</enscript>
     48
     49==== tuple
     50
     51<procedure>(tuple . args)</procedure>
     52
     53function (result)
     54
     55<enscript highlight=scheme>
     56
     57(tuple . args)
     58  #t
     59  (%tuple? result)
     60
     61</enscript>
     62
     63==== tuple->list
     64
     65<procedure>(tuple->list tup)</procedure>
     66
     67function (result)
     68
     69<enscript highlight=scheme>
     70
     71(tuple->list tup)
     72  (%tuple? tup)
     73  (list? result)
     74
     75</enscript>
     76
     77==== tuple->vector
     78
     79<procedure>(tuple->vector tup)</procedure>
     80
     81function (result)
     82
     83<enscript highlight=scheme>
     84
     85(tuple->vector tup)
     86  (%tuple? tup)
     87  (vector? result)
     88
     89</enscript>
     90
     91==== tuple-append
     92
     93<procedure>(tuple-append . tups)</procedure>
     94
     95function (result)
     96
     97<enscript highlight=scheme>
     98
     99(tuple-append . tups)
     100  ((list-of? %tuple?) tups)
     101  (and (%tuple? result) (= (tuple-length result) (apply + (map tuple-length tups))))
     102
     103</enscript>
     104
     105==== tuple-butleft
     106
     107<procedure>(tuple-butleft tup)</procedure>
     108
     109function (result)
     110
     111<enscript highlight=scheme>
     112
     113(tuple-butleft tup)
     114  (and (%tuple? tup) (positive? (%tuple-length tup)))
     115  (and (%tuple result) (= (%tuple-length result) (- (%tuple-length tup) 1)))
     116
     117</enscript>
     118
     119==== tuple-butright
     120
     121<procedure>(tuple-butright tup)</procedure>
     122
     123function (result)
     124
     125<enscript highlight=scheme>
     126
     127(tuple-butright tup)
     128  (and (%tuple? tup) (positive? (%tuple-length tup)))
     129  (and (%tuple result) (= (%tuple-length result) (- (%tuple-length tup) 1)))
     130
     131</enscript>
     132
     133==== tuple-cons-left
     134
     135<procedure>(tuple-cons-left arg tup)</procedure>
     136
     137function (result)
     138
     139<enscript highlight=scheme>
     140
     141(tuple-cons-left arg tup)
     142  (%tuple? tup)
     143  (and (%tuple result) (= (%tuple-length result) (+ (%tuple-length tup) 1)))
     144
     145</enscript>
     146
     147==== tuple-cons-right
     148
     149<procedure>(tuple-cons-right arg tup)</procedure>
     150
     151function (result)
     152
     153<enscript highlight=scheme>
     154
     155(tuple-cons-right arg tup)
     156  (%tuple? tup)
     157  (and (%tuple result) (= (%tuple-length result) (+ (%tuple-length tup) 1)))
     158
     159</enscript>
     160
     161==== tuple-copy
     162
     163<procedure>(tuple-copy tup)</procedure>
     164
     165function (result)
     166
     167<enscript highlight=scheme>
     168
     169(tuple-copy tup)
     170  (%tuple tup)
     171  (%tuple result)
     172
     173</enscript>
     174
     175==== tuple-empty?
     176
     177<procedure>(tuple-empty? xpr)</procedure>
     178
     179function (result)
     180
     181<enscript highlight=scheme>
     182
     183(tuple-empty? xpr)
     184  #t
     185  (boolean? result)
     186
     187</enscript>
     188
     189==== tuple-eq?
     190
     191<procedure>(tuple-eq? tup0 tup1)</procedure>
     192
     193function (result)
     194
     195<enscript highlight=scheme>
     196
     197(tuple-eq? tup0 tup1)
     198  (and (%tuple? tup0) (%tuple? tup1))
     199  (boolean? result)
     200
     201</enscript>
     202
     203==== tuple-eql?
     204
     205<procedure>(tuple-eql? eql? tup0 tup1)</procedure>
     206
     207function (result)
     208
     209<enscript highlight=scheme>
     210
     211(tuple-eql? eql? tup0 tup1)
     212  (and (procedure? eql?) (%tuple? tup0) (%tuple? tup1))
     213  (boolean? result)
     214
     215</enscript>
     216
     217==== tuple-equal?
     218
     219<procedure>(tuple-equal? tup0 tup1)</procedure>
     220
     221function (result)
     222
     223<enscript highlight=scheme>
     224
     225(tuple-equal? tup0 tup1)
     226  (and (%tuple? tup0) (%tuple? tup1))
     227  (boolean? result)
     228
     229</enscript>
     230
     231==== tuple-eqv?
     232
     233<procedure>(tuple-eqv? tup0 tup1)</procedure>
     234
     235function (result)
     236
     237<enscript highlight=scheme>
     238
     239(tuple-eqv? tup0 tup1)
     240  (and (%tuple? tup0) (%tuple? tup1))
     241  (boolean? result)
     242
     243</enscript>
     244
     245==== tuple-find
     246
     247<procedure>(tuple-find ok? tup)</procedure>
     248
     249function (result)
     250
     251<enscript highlight=scheme>
     252
     253(tuple-find ok? tup)
     254  (and (procedure? ok?) (%tuple? tup))
     255  (or (not result) (and (cardinal? result) (< result (%tuple-length tup)) "index of found item"))
     256
     257</enscript>
     258
     259==== tuple-for-each
     260
     261<procedure>(tuple-for-each proc tup . tups)</procedure>
     262
     263command ((old new (lambda (proc tup . tups) #t)))
     264
     265<enscript highlight=scheme>
     266
     267(tuple-for-each proc tup . tups)
     268  (and (procedure? proc) (%tuple tup) ((list-of? %tuple?) tups) (apply = (%tuple-length tup) (map %tuple-length tups)))
     269  "proc applied to each item"
     270
     271</enscript>
     272
     273==== tuple-from-upto
     274
     275<procedure>(tuple-from-upto tup . interval)</procedure>
     276
     277function (result)
     278
     279<enscript highlight=scheme>
     280
     281(tuple-from-upto tup . interval)
     282  (and (%tuple tup) ((list-of? (lambda (x) (and (cardinal? x) (<= x (%tuple-length tup))))) interval) (<= (length interval) 2) (apply <= 0 interval))
     283  (and (%tuple? result) (= (%tuple-length result) (case (length interval) ((0) (%tuple-length tup)) ((1) (- (%tuple-length tup) (car interval))) ((2) (- (cadr interval) (car interval))))))
     284
     285</enscript>
     286
     287==== tuple-head
     288
     289<procedure>(tuple-head tup n)</procedure>
     290
     291function (result)
     292
     293<enscript highlight=scheme>
     294
     295(tuple-head tup n)
     296  (and (%tuple? tup) (<= n (%tuple-length tup)))
     297  (and (%tuple result) (= (%tuple-length result) n))
     298
     299</enscript>
     300
     301==== tuple-left
     302
     303<procedure>(tuple-left tup)</procedure>
     304
     305function (result)
     306
     307<enscript highlight=scheme>
     308
     309(tuple-left tup)
     310  (and (%tuple? tup) (positive? (%tuple-length tup)))
     311  "tup's leftmost item"
     312
     313</enscript>
     314
     315==== tuple-length
     316
     317<procedure>(tuple-length tup)</procedure>
     318
     319function (result)
     320
     321<enscript highlight=scheme>
     322
     323(tuple-length tup)
     324  (%tuple? tup)
     325  (cardinal? result)
     326
     327</enscript>
     328
     329==== tuple-map
     330
     331<procedure>(tuple-map fn tup . tups)</procedure>
     332
     333function (result)
     334
     335<enscript highlight=scheme>
     336
     337(tuple-map fn tup . tups)
     338  (and (procedure? fn) (%tuple? tup) ((list-of? %tuple?) tups) (apply = (%tuple-length tup) (map %tuple-length tups)))
     339  (and (%tuple? result) (= (%tuple-length tup) (%tuple-length result)))
     340
     341</enscript>
     342
     343==== tuple-of?
     344
     345<procedure>(tuple-of? ok?)</procedure>
     346
     347function (result)
     348
     349<enscript highlight=scheme>
     350
     351(tuple-of? ok?)
     352  (procedure? ok?)
     353  (procedure? result)
     354
     355</enscript>
     356
     357==== tuple-ref
     358
     359<procedure>(tuple-ref tup n)</procedure>
     360
     361function (result)
     362
     363<enscript highlight=scheme>
     364
     365(tuple-ref tup n)
     366  (and (%tuple? tup) (cardinal? n) (< -1 n (%tuple-length tup)))
     367  "tup's nth item"
     368
     369</enscript>
     370
     371==== tuple-reverse
     372
     373<procedure>(tuple-reverse tup)</procedure>
     374
     375function (result)
     376
     377<enscript highlight=scheme>
     378
     379(tuple-reverse tup)
     380  (%tuple? tup)
     381  (and (%tuple result) (= (%tuple-length result) (%tuple-length tup)))
     382
     383</enscript>
     384
     385==== tuple-right
     386
     387<procedure>(tuple-right tup)</procedure>
     388
     389function (result)
     390
     391<enscript highlight=scheme>
     392
     393(tuple-right tup)
     394  (and (%tuple? tup) (positive? (%tuple-length tup)))
     395  "tup's rightmost item"
     396
     397</enscript>
     398
     399==== tuple-tail
     400
     401<procedure>(tuple-tail tup n)</procedure>
     402
     403function (result)
     404
     405<enscript highlight=scheme>
     406
     407(tuple-tail tup n)
     408  (and (%tuple? tup) (<= n (%tuple-length tup)))
     409  (and (%tuple result) (= (%tuple-length result) (- (%tuple-length tup) n)))
     410
     411</enscript>
     412
     413==== tuple?
     414
     415<procedure>(tuple? xpr)</procedure>
     416
     417function (result)
     418
     419<enscript highlight=scheme>
     420
     421(tuple? xpr)
     422  #t
     423  (boolean? result)
     424
     425</enscript>
     426
     427==== vector->tuple
     428
     429<procedure>(vector->tuple vec)</procedure>
     430
     431function (result)
     432
     433<enscript highlight=scheme>
     434
     435(vector->tuple vec)
     436  (vector? vec)
     437  (and (%tuple? result) (= (%tuple-length result) (vector-length vec)))
     438
     439</enscript>
     440
     441=== Module triples
     442
     443==== triple
     444
     445<procedure>(triple x y z)</procedure>
     446
     447function (result)
     448
     449<enscript highlight=scheme>
     450
     451(triple x y z)
     452  #t
     453  (%triple? result)
     454
     455</enscript>
     456
     457==== triple->tuple
     458
     459<procedure>(triple->tuple trp)</procedure>
     460
     461function (result)
     462
     463<enscript highlight=scheme>
     464
     465(triple->tuple trp)
     466  (%triple? trp)
     467  (and (%tuple? result) (= (%tuple-length result) 3))
     468
     469</enscript>
     470
     471==== triple-eq?
     472
     473<procedure>(triple-eq? trp0 trp1)</procedure>
     474
     475function (result)
     476
     477<enscript highlight=scheme>
     478
     479(triple-eq? trp0 trp1)
     480  (and (%triple? trp0) (%triple? trp1))
     481  (boolean? result)
     482
     483</enscript>
     484
     485==== triple-eql?
     486
     487<procedure>(triple-eql? eql? trp0 trp1)</procedure>
     488
     489function (result)
     490
     491<enscript highlight=scheme>
     492
     493(triple-eql? eql? trp0 trp1)
     494  (and (procedure? eql?) (%triple? trp0) (%triple? trp1))
     495  (boolean? result)
     496
     497</enscript>
     498
     499==== triple-equal?
     500
     501<procedure>(triple-equal? trp0 trp1)</procedure>
     502
     503function (result)
     504
     505<enscript highlight=scheme>
     506
     507(triple-equal? trp0 trp1)
     508  (and (%triple? trp0) (%triple? trp1))
     509  (boolean? result)
     510
     511</enscript>
     512
     513==== triple-eqv?
     514
     515<procedure>(triple-eqv? trp0 trp1)</procedure>
     516
     517function (result)
     518
     519<enscript highlight=scheme>
     520
     521(triple-eqv? trp0 trp1)
     522  (and (%triple? trp0) (%triple? trp1))
     523  (boolean? result)
     524
     525</enscript>
     526
     527==== triple-left
     528
     529<procedure>(triple-left trp)</procedure>
     530
     531function (result)
     532
     533<enscript highlight=scheme>
     534
     535(triple-left trp)
     536  (%triple? trp)
     537  "leftmost item"
     538
     539</enscript>
     540
     541==== triple-middle
     542
     543<procedure>(triple-middle trp)</procedure>
     544
     545function (result)
     546
     547<enscript highlight=scheme>
     548
     549(triple-middle trp)
     550  (%triple? trp)
     551  "item in the middle"
     552
     553</enscript>
    38554
    39555==== triple-right
    40556
    41 <procedure>(triple-right tup)</procedure>
    42 
    43 returns the right item of a triple
    44 
    45 ==== triple-middle
    46 
    47 <procedure>(triple-middle tup)</procedure>
    48 
    49 returns the middle item of a triple
    50 
    51 ==== triple-left
    52 
    53 <procedure>(triple-left tup)</procedure>
    54 
    55 returns the left item of a triple
    56 
    57 ==== triple
    58 
    59 <procedure>(triple x y z)</procedure>
    60 
    61 constructor for a tuple storing two items
     557<procedure>(triple-right trp)</procedure>
     558
     559function (result)
     560
     561<enscript highlight=scheme>
     562
     563(triple-right trp)
     564  (%triple? trp)
     565  "rightmost item"
     566
     567</enscript>
    62568
    63569==== triple?
     
    65571<procedure>(triple? x)</procedure>
    66572
    67 tests for a tuple storing two items
     573function (result)
     574
     575<enscript highlight=scheme>
     576
     577(triple? x)
     578  #t
     579  (boolean? result)
     580
     581</enscript>
     582
     583=== Module couples
     584
     585==== couple
     586
     587<procedure>(couple x y)</procedure>
     588
     589function (result)
     590
     591<enscript highlight=scheme>
     592
     593(couple x y)
     594  #t
     595  (%couple? result)
     596
     597</enscript>
     598
     599==== couple->tuple
     600
     601<procedure>(couple->tuple cpl)</procedure>
     602
     603function (result)
     604
     605<enscript highlight=scheme>
     606
     607(couple->tuple cpl)
     608  (%couple? cpl)
     609  (and (%tuple? result) (= (%tuple-length result) 2))
     610
     611</enscript>
     612
     613==== couple-eq?
     614
     615<procedure>(couple-eq? cpl0 cpl1)</procedure>
     616
     617function (result)
     618
     619<enscript highlight=scheme>
     620
     621(couple-eq? cpl0 cpl1)
     622  (and (%couple? cpl0) (%couple? cpl1))
     623  (boolean? result)
     624
     625</enscript>
     626
     627==== couple-eql?
     628
     629<procedure>(couple-eql? eql? cpl0 cpl1)</procedure>
     630
     631function (result)
     632
     633<enscript highlight=scheme>
     634
     635(couple-eql? eql? cpl0 cpl1)
     636  (and (procedure? eql?) (%couple? cpl0) (%couple? cpl1))
     637  (boolean? result)
     638
     639</enscript>
     640
     641==== couple-equal?
     642
     643<procedure>(couple-equal? cpl0 cpl1)</procedure>
     644
     645function (result)
     646
     647<enscript highlight=scheme>
     648
     649(couple-equal? cpl0 cpl1)
     650  (and (%couple? cpl0) (%couple? cpl1))
     651  (boolean? result)
     652
     653</enscript>
     654
     655==== couple-eqv?
     656
     657<procedure>(couple-eqv? cpl0 cpl1)</procedure>
     658
     659function (result)
     660
     661<enscript highlight=scheme>
     662
     663(couple-eqv? cpl0 cpl1)
     664  (and (%couple? cpl0) (%couple? cpl1))
     665  (boolean? result)
     666
     667</enscript>
     668
     669==== couple-left
     670
     671<procedure>(couple-left cpl)</procedure>
     672
     673function (result)
     674
     675<enscript highlight=scheme>
     676
     677(couple-left cpl)
     678  (%couple? cpl)
     679  "leftmost item"
     680
     681</enscript>
    68682
    69683==== couple-right
    70684
    71 <procedure>(couple-right tup)</procedure>
    72 
    73 returns the right item of a couple
    74 
    75 ==== couple-left
    76 
    77 <procedure>(couple-left tup)</procedure>
    78 
    79 returns the left item of a couple
    80 
    81 ==== couple
    82 
    83 <procedure>(couple x y)</procedure>
    84 
    85 constructor for a tuple storing two items
     685<procedure>(couple-right cpl)</procedure>
     686
     687function (result)
     688
     689<enscript highlight=scheme>
     690
     691(couple-right cpl)
     692  (%couple? cpl)
     693  "rightmost item"
     694
     695</enscript>
    86696
    87697==== couple?
     
    89699<procedure>(couple? x)</procedure>
    90700
    91 tests for a tuple storing two items
     701function (result)
     702
     703<enscript highlight=scheme>
     704
     705(couple? x)
     706  #t
     707  (boolean? result)
     708
     709</enscript>
     710
     711=== Module singles
     712
     713==== single
     714
     715<procedure>(single x)</procedure>
     716
     717function (result)
     718
     719<enscript highlight=scheme>
     720
     721(single x)
     722  #t
     723  (%single? result)
     724
     725</enscript>
     726
     727==== single-eq?
     728
     729<procedure>(single-eq? sgl0 sgl1)</procedure>
     730
     731function (result)
     732
     733<enscript highlight=scheme>
     734
     735(single-eq? sgl0 sgl1)
     736  (and (%single? sgl0) (%single? sgl1))
     737  (boolean? result)
     738
     739</enscript>
     740
     741==== single-eql?
     742
     743<procedure>(single-eql? eql? sgl0 sgl1)</procedure>
     744
     745function (result)
     746
     747<enscript highlight=scheme>
     748
     749(single-eql? eql? sgl0 sgl1)
     750  (and (procedure? eql?) (%single? sgl0) (%single? sgl1))
     751  (boolean? result)
     752
     753</enscript>
     754
     755==== single-equal?
     756
     757<procedure>(single-equal? sgl0 sgl1)</procedure>
     758
     759function (result)
     760
     761<enscript highlight=scheme>
     762
     763(single-equal? sgl0 sgl1)
     764  (and (%single? sgl0) (%single? sgl1))
     765  (boolean? result)
     766
     767</enscript>
     768
     769==== single-eqv?
     770
     771<procedure>(single-eqv? sgl0 sgl1)</procedure>
     772
     773function (result)
     774
     775<enscript highlight=scheme>
     776
     777(single-eqv? sgl0 sgl1)
     778  (and (%single? sgl0) (%single? sgl1))
     779  (boolean? result)
     780
     781</enscript>
     782
     783==== single-ref
     784
     785<procedure>(single-ref sg)</procedure>
     786
     787function (result)
     788
     789<enscript highlight=scheme>
     790
     791(single-ref sg)
     792  (%single? sg)
     793  "sg's stored item"
     794
     795</enscript>
    92796
    93797==== single-set!
    94798
    95 <procedure>(single-set! sg arg)</procedure>
    96 
    97 <enscript highlight=scheme>
    98 (domain (%single? sg) (true? arg))
    99 (effect (state (%tuple-state sg) arg))
    100 </enscript>
    101 
    102 replaces state of sg with arg
    103 
    104 ==== single-ref
    105 
    106 <procedure>(single-ref sg)</procedure>
    107 
    108 <enscript highlight=scheme>
    109 (domain (%single? sg))
    110 </enscript>
    111 
    112 returns the state of the single object sg
    113 
    114 ==== single
    115 
    116 <procedure>(single xpr)</procedure>
    117 
    118 <enscript highlight=scheme>
    119 (domain (true? xpr))
    120 (range (%single? result))
    121 </enscript>
    122 
    123 package xpr into a box so that it can be modified
     799<procedure>(single-set! sg x)</procedure>
     800
     801command ((old new (lambda (sg x) (%single-ref sg))))
     802
     803<enscript highlight=scheme>
     804
     805(single-set! sg x)
     806  (%single? sg)
     807  (equal? new x)
     808
     809</enscript>
    124810
    125811==== single?
    126812
    127 <procedure>(single? xpr)</procedure>
    128 
    129 check, if xpr evaluates to a single
    130 
    131 ==== empty
    132 
    133 <procedure>(empty)</procedure>
    134 
    135 constructor for an empty tuple
    136 
    137 ==== empty?
    138 
    139 <procedure>(empty? x)</procedure>
    140 
    141 tests for an empty tuple
    142 
    143 ==== tuple-for-each
    144 
    145 <procedure>(tuple-for-each proc tup)</procedure>
    146 
    147 <enscript highlight=scheme>
    148 (domain (%tuple? tup) (procedure? proc) a one parameter procedure)
    149 </enscript>
    150 
    151 apply a one parameter procedure to each item of tup
    152 
    153 ==== tuple->list
    154 
    155 <procedure>(tuple->list tup)</procedure>
    156 
    157 <enscript highlight=scheme>
    158 (domain (%tuple? tup))
    159 (range (list? result))
    160 </enscript>
    161 
    162 transforms a tuple into a list
    163 
    164 ==== tuple-find
    165 
    166 <procedure>(tuple-find tup item compare?)</procedure>
    167 
    168 <enscript highlight=scheme>
    169 (domain (%tuple? tup) (procedure? compare?) a two parameter predicate)
    170 (range (or (not result) (and (cardinal? result) (< result (%tuple-length tup)))))
    171 </enscript>
    172 
    173 checks by comparing with compare? if item is contained in tup
    174 
    175 ==== tuple-right
    176 
    177 <procedure>(tuple-right tup)</procedure>
    178 
    179 <enscript highlight=scheme>
    180 (domain (%tuple? tup) (>= (%tuple-length tup) 2))
    181 </enscript>
    182 
    183 returns the rightmost item of tup
    184 
    185 ==== tuple-left
    186 
    187 <procedure>(tuple-left tup)</procedure>
    188 
    189 <enscript highlight=scheme>
    190 (domain (%tuple? tup) (positive? (%tuple-length tup)))
    191 </enscript>
    192 
    193 returns the leftmost item of tup
    194 
    195 ==== tuple-ref
    196 
    197 <procedure>(tuple-ref tup n)</procedure>
    198 
    199 <enscript highlight=scheme>
    200 (domain (%tuple? tup) (cardinal? n) (< n (%tuple-length tup)))
    201 </enscript>
    202 
    203 returns the n'th item of tup, counting from zero
    204 
    205 ==== tuple-length
    206 
    207 <procedure>(tuple-length tup)</procedure>
    208 
    209 <enscript highlight=scheme>
    210 (domain (%tuple? tup))
    211 (range (cardinal? result))
    212 </enscript>
    213 
    214 returns the number of tuple items
    215 
    216 ==== tuple-copy
    217 
    218 <procedure>(tuple-copy tup . interval)</procedure>
    219 
    220 <enscript highlight=scheme>
    221 (domain (%tuple? tup)
    222                                 (<= (length interval) 2)
    223                                 ((list-of? cardinal?) interval)
    224                                 (apply <= (append interval (list (%tuple-length tup)))))
    225 (range (%tuple? result))
    226 </enscript>
    227 
    228 constructing a subtuple with tup data from interval
    229 
    230 ==== tuple-append
    231 
    232 <procedure>(tuple-append . tups)</procedure>
    233 
    234 <enscript highlight=scheme>
    235 (domain ((list-of? tuple?) tups))
    236 (range (%tuple? result))
    237 </enscript>
    238 
    239 constructs a new tuple by concatenating several others
    240 
    241 ==== tuple-map
    242 
    243 <procedure>(tuple-map fn tup)</procedure>
    244 
    245 <enscript highlight=scheme>
    246 (domain (%tuple? tup) (procedure? fn) a one parameter function)
    247 (range (%tuple? result))
    248 </enscript>
    249 
    250 constructs a new tuple by mapping each item of tup with function fn
    251 
    252 ==== list->tuple
    253 
    254 <procedure>(list->tuple lst)</procedure>
    255 
    256 <enscript highlight=scheme>
    257 (domain (list? lst))
    258 (range (%tuple? result))
    259 </enscript>
    260 
    261 transforms a list into a tuple
    262 
    263 ==== tuple
    264 
    265 <procedure>(tuple . args)</procedure>
    266 
    267 <enscript highlight=scheme>
    268 (domain (true? args))
    269 (range (%tuple? result))
    270 </enscript>
    271 
    272 tuple constructor
    273 
    274 ==== tuple-of?
    275 
    276 <procedure>(tuple-of? ok?)</procedure>
    277 
    278 <enscript highlight=scheme>
    279 (domain (procedure? ok?) ok? is a one parameter predicate)
    280 (range (procedure? result) result is a one parameter predicate)
    281 </enscript>
    282 
    283 checks, if each tuple item satisfies predicate ok?
    284 
    285 ==== tuple?
    286 
    287 <procedure>(tuple? xpr)</procedure>
    288 
    289 checks if xpr evaluates to a tuple
    290 
     813<procedure>(single? x)</procedure>
     814
     815function (result)
     816
     817<enscript highlight=scheme>
     818
     819(single? x)
     820  #t
     821  (boolean? result)
     822
     823</enscript>
    291824
    292825== Requirements
    293826
    294 [[contracts]]
     827[[dbc]]
    295828
    296829== Last update
    297830
    298 Aug 02, 2012
     831Jan 31, 2013
    299832
    300833== Author
     
    304837== License
    305838
    306  Copyright (c) 2012, Juergen Lorenz
     839 Copyright (c) 2012-2013, Juergen Lorenz
    307840 All rights reserved.
    308841
     
    335868== Version History
    336869
     870; 1.0 : dependency on contracts changed to dbc, moduls further split, addition routines
    337871; 0.8 : code split into two modules
    338872; 0.7 : single-state and single-state! renamed to single-ref and single-set!
Note: See TracChangeset for help on using the changeset viewer.