Changeset 27163 in project
 Timestamp:
 08/02/12 18:54:21 (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

wiki/eggref/4/tuples
r26087 r27163 10 10 == Documentation 11 11 12 In this implementation tuples are implemented in the Design by Contract style, i.e. using the contracts module. A corollary of this is, that the documentation is included in the module. By convention, there is a routine with the module's name, tuples, which when called with no argument 13 14 (tuples) 15 16 shows the exported contractchecked symbols, and called with one of its symbols, e.g. 17 18 (tuples 'tuple>list) 19 20 shows the documentation of this symbol in all it's glory, i.e. together with callstructure, docstring, assumptions and propositions. 21 22 Note that most contractchecked routines have brethren whith identical signature which are not contractchecked and are not exported. They are prefixed with an % sign and used internally, especially for contractchecking, thus avoiding doublechecking. 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. 23 28 24 29 Another way to get the complete documentation is to use printdoclist from the contracts module. Issuing 25 30 31 <enscript highlight=scheme> 26 32 (import tuples (only contracts printdoclist)) 27 33 (withoutputtofile "tuples.docu" (lambda () (printdoclist))) 28 29 you'll get a file tuples.docu with the following content 30 31 tripleright 32  33 (tripleright tup) 34 returns the right item of a triple 35 36 triplemiddle 37  38 (triplemiddle tup) 39 returns the middle item of a triple 40 41 tripleleft 42  43 (tripleleft tup) 44 returns the left item of a triple 45 46 triple 47  48 (triple x y z) 49 constructor for a tuple storing two items 50 51 triple? 52  53 (triple? x) 54 tests for a tuple storing two items 55 56 coupleright 57  58 (coupleright tup) 59 returns the right item of a couple 60 61 coupleleft 62  63 (coupleleft tup) 64 returns the left item of a couple 65 66 couple 67  68 (couple x y) 69 constructor for a tuple storing two items 70 71 couple? 72  73 (couple? x) 74 tests for a tuple storing two items 75 76 singleset! 77  78 (singleset! sg arg) 79 replaces state of sg with arg 80 (domain (%single? sg) (true? arg)) 81 (effect (state (%tuplestate sg) arg)) 82 83 singleref 84  85 (singleref sg) 86 returns the state of the single object sg 87 (domain (%single? sg)) 88 89 single 90  91 (single xpr) 92 package xpr into a box so that it can be modified 93 (domain (true? xpr)) 94 (range (%single? result)) 95 96 single? 97  98 (single? xpr) 99 check, if xpr evaluates to a single 100 101 empty 102  103 (empty) 104 constructor for an empty tuple 105 106 empty? 107  108 (empty? x) 109 tests for an empty tuple 110 111 tupleforeach 112  113 (tupleforeach proc tup) 114 apply a one parameter procedure to each item of tup 115 (domain (%tuple? tup) (procedure? proc) a one parameter procedure) 116 117 tuple>list 118  119 (tuple>list tup) 120 transforms a tuple into a list 121 (domain (%tuple? tup)) 122 (range (list? result)) 123 124 tuplefind 125  126 (tuplefind tup item compare?) 127 checks by comparing with compare? if item is contained in tup 128 (domain (%tuple? tup) (procedure? compare?) a two parameter predicate) 129 (range (or (not result) (and (cardinal? result) (< result (%tuplelength tup))))) 130 131 tupleright 132  133 (tupleright tup) 134 returns the rightmost item of tup 135 (domain (%tuple? tup) (>= (%tuplelength tup) 2)) 136 137 tupleleft 138  139 (tupleleft tup) 140 returns the leftmost item of tup 141 (domain (%tuple? tup) (positive? (%tuplelength tup))) 142 143 tupleref 144  145 (tupleref tup n) 146 returns the n'th item of tup, counting from zero 147 (domain (%tuple? tup) (cardinal? n) (< n (%tuplelength tup))) 148 149 tuplelength 150  151 (tuplelength tup) 152 returns the number of tuple items 153 (domain (%tuple? tup)) 154 (range (cardinal? result)) 155 156 tuplecopy 157  158 (tuplecopy tup . interval) 159 constructing a subtuple with tup data from interval 160 (domain (%tuple? tup) 161 (<= (length interval) 2) 162 ((listof? cardinal?) interval) 163 (apply <= (append interval (list (%tuplelength tup))))) 164 (range (%tuple? result)) 165 166 tupleappend 167  168 (tupleappend . tups) 169 constructs a new tuple by concatenating several others 170 (domain ((listof? tuple?) tups)) 171 (range (%tuple? result)) 172 173 tuplemap 174  175 (tuplemap fn tup) 176 constructs a new tuple by mapping each item of tup with function fn 177 (domain (%tuple? tup) (procedure? fn) a one parameter function) 178 (range (%tuple? result)) 179 180 list>tuple 181  182 (list>tuple lst) 183 transforms a list into a tuple 184 (domain (list? lst)) 185 (range (%tuple? result)) 186 187 tuple 188  189 (tuple . args) 190 tuple constructor 191 (domain (true? args)) 192 (range (%tuple? result)) 193 194 tupleof? 195  196 (tupleof? ok?) 197 checks, if each tuple item satisfies predicate ok? 198 (domain (procedure? ok?) ok? is a one parameter predicate) 199 (range (procedure? result) result is a one parameter predicate) 200 201 tuple? 202  203 (tuple? xpr) 204 checks if xpr evaluates to a tuple 34 </enscript> 35 36 you'll get a file tuples.docu which is the basis for the following 37 documentation. 38 39 ==== tripleright 40 41 <procedure>(tripleright tup)</procedure> 42 43 returns the right item of a triple 44 45 ==== triplemiddle 46 47 <procedure>(triplemiddle tup)</procedure> 48 49 returns the middle item of a triple 50 51 ==== tripleleft 52 53 <procedure>(tripleleft 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 62 63 ==== triple? 64 65 <procedure>(triple? x)</procedure> 66 67 tests for a tuple storing two items 68 69 ==== coupleright 70 71 <procedure>(coupleright tup)</procedure> 72 73 returns the right item of a couple 74 75 ==== coupleleft 76 77 <procedure>(coupleleft 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 86 87 ==== couple? 88 89 <procedure>(couple? x)</procedure> 90 91 tests for a tuple storing two items 92 93 ==== singleset! 94 95 <procedure>(singleset! sg arg)</procedure> 96 97 <enscript highlight=scheme> 98 (domain (%single? sg) (true? arg)) 99 (effect (state (%tuplestate sg) arg)) 100 </enscript> 101 102 replaces state of sg with arg 103 104 ==== singleref 105 106 <procedure>(singleref 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 124 125 ==== single? 126 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 ==== tupleforeach 144 145 <procedure>(tupleforeach 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 ==== tuplefind 165 166 <procedure>(tuplefind 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 (%tuplelength tup))))) 171 </enscript> 172 173 checks by comparing with compare? if item is contained in tup 174 175 ==== tupleright 176 177 <procedure>(tupleright tup)</procedure> 178 179 <enscript highlight=scheme> 180 (domain (%tuple? tup) (>= (%tuplelength tup) 2)) 181 </enscript> 182 183 returns the rightmost item of tup 184 185 ==== tupleleft 186 187 <procedure>(tupleleft tup)</procedure> 188 189 <enscript highlight=scheme> 190 (domain (%tuple? tup) (positive? (%tuplelength tup))) 191 </enscript> 192 193 returns the leftmost item of tup 194 195 ==== tupleref 196 197 <procedure>(tupleref tup n)</procedure> 198 199 <enscript highlight=scheme> 200 (domain (%tuple? tup) (cardinal? n) (< n (%tuplelength tup))) 201 </enscript> 202 203 returns the n'th item of tup, counting from zero 204 205 ==== tuplelength 206 207 <procedure>(tuplelength 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 ==== tuplecopy 217 218 <procedure>(tuplecopy tup . interval)</procedure> 219 220 <enscript highlight=scheme> 221 (domain (%tuple? tup) 222 (<= (length interval) 2) 223 ((listof? cardinal?) interval) 224 (apply <= (append interval (list (%tuplelength tup))))) 225 (range (%tuple? result)) 226 </enscript> 227 228 constructing a subtuple with tup data from interval 229 230 ==== tupleappend 231 232 <procedure>(tupleappend . tups)</procedure> 233 234 <enscript highlight=scheme> 235 (domain ((listof? tuple?) tups)) 236 (range (%tuple? result)) 237 </enscript> 238 239 constructs a new tuple by concatenating several others 240 241 ==== tuplemap 242 243 <procedure>(tuplemap 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 ==== tupleof? 275 276 <procedure>(tupleof? 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 205 290 206 291 … … 211 296 == Last update 212 297 213 Mar 07, 2012298 Aug 02, 2012 214 299 215 300 == Author … … 250 335 == Version History 251 336 337 ; 0.8 : code split into two modules 252 338 ; 0.7 : singlestate and singlestate! renamed to singleref and singleset! 253 339 ; 0.6 : contracts rewritten
Note: See TracChangeset
for help on using the changeset viewer.