Changeset 18915 in project
 Timestamp:
 07/21/10 20:38:41 (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

wiki/eggref/4/combinators
r14119 r18915 10 10 == Documentation 11 11 12 === Section Combinators 13 14 ==== Usage 15 16 <enscript language=scheme> 17 (requireextension sectioncombinators) 18 </enscript> 19 20 ==== leftsection 21 22 <procedure>(leftsection FUNC ARG0 ...) => {{procedure}}</procedure> 23 24 Returns a procedure that partially applies some of its arguments starting from the left. 25 26 {{FUNC}} a procedure. 27 28 {{ARG0 ...}} some prefix of the arguments for {{FUNC}}. 29 30 Returns a partially curried procedure. 31 32 ==== rightsection 33 34 <procedure>(rightsection FUNC ARG0 ...) => {{procedure}}</procedure> 35 36 Returns a procedure that partially applies some of its arguments starting from the right. 37 38 {{FUNC}} a procedure. 39 40 {{ARG0 ...}} some reversed suffix of the arguments for {{FUNC}}. 41 42 Returns a partially curried procedure. 43 12 44 13 45 === Sort Combinators 14 46 47 ==== Usage 48 49 <enscript language=scheme> 50 (requireextension sortcombinators) 51 </enscript> 52 53 ==== Examples 54 55 <enscript highlight=scheme> 56 (group/key identity '(1 2 3 3 4 4 4)) ;=> ((1) (2) (3 3) (4 4 4)) 57 58 (group/key car '((a 1) (a 2) (b 1))) ;=> '(((a 1) (a 2)) ((b 1))) 59 60 (sort '(("a" . 1) ("z" . 3) ("b" . 2)) (makelessthan/key first stringci<?)) ;=> (("a" . 1) ("b" . 2) ("z" . 3)) 61 </enscript> 62 15 63 ==== group/key 16 64 17 <procedure>(group/key KEYPROC LYST [EQUALITY equal?])</procedure>65 <procedure>(group/key FUNC LYST [EQUALITY equal?])</procedure> 18 66 19 67 Groups a {{LYST}} of elements by some key attribute. Uses the singleargument 20 {{ KEYPROC}} to retrieve key values & the {{EQUALITY}} procedureto compare68 {{FUNC}} to retrieve key values & the {{EQUALITY}} function to compare 21 69 them. 22 70 71 The {{LYST}} must be in sorted order with respect to the key! 72 23 73 Returns a list of grouped elements. 24 74 25 75 ==== makelessthan/key 26 76 27 <procedure>(makelessthan/key KEYPROC [LESSTHAN <])</procedure>28 29 Returns a twoargument procedure that uses the singleargument {{ KEYPROC}} to77 <procedure>(makelessthan/key FUNC [LESSTHAN <]) => {{procedure/2}}</procedure> 78 79 Returns a twoargument procedure that uses the singleargument {{FUNC}} to 30 80 retrieve key values & the twoargument {{LESSTHAN}} procedure to compare them. 31 81 32 82 ==== makeequal/key 33 83 34 <procedure>(makeequal/key KEYPROC [EQUAL =])</procedure>35 36 Returns a twoargument procedure that uses the singleargument {{ KEYPROC}} to84 <procedure>(makeequal/key FUNC [EQUAL =]) => {{procedure/2}}</procedure> 85 86 Returns a twoargument procedure that uses the singleargument {{FUNC}} to 37 87 retrieve key values & the twoargument {{EQUAL}} procedure to compare them. 38 88 … … 40 90 === Logical Combinators 41 91 92 ==== Usage 93 94 <enscript language=scheme> 95 (requireextension logicalcombinators) 96 </enscript> 97 42 98 ==== andf 43 99 44 100 <procedure>(andf OBJECT...)</procedure> 101 102 Eager version of {{and}}. 45 103 46 104 Returns last {{(not #f)}} {{OBJECT}} when all {{OBJECT...}} are {{(not #f)}}, … … 51 109 <procedure>(orf OBJECT...)</procedure> 52 110 111 Eager version of {{or}}. 112 53 113 Returns first {{(not #f)}} {{OBJECT}}, {{#f}} otherwise. 54 114 115 55 116 === Stack Combinators 56 117 118 ==== Usage 119 120 <enscript language=scheme> 121 (requireextension stackcombinators) 122 </enscript> 123 57 124 {{C}} is a combinator {{function}}. 58 125 … … 63 130 ==== uni 64 131 65 <procedure>(uni X F C) => OBJECT</procedure>132 <procedure>(uni X F C) => {{procedure}}</procedure> 66 133 67 134 Returns the result of {{(C (F X))}}. 68 135 69 <procedure>(uni F C) => PROCEDURE/1</procedure>70 <procedure>(uni C) => PROCEDURE/1</procedure>71 <procedure>(uni) => PROCEDURE/1</procedure>136 <procedure>(uni F C) => {{procedure/1}}</procedure> 137 <procedure>(uni C) => {{procedure/1}}</procedure> 138 <procedure>(uni) => {{procedure/1}}</procedure> 72 139 73 140 Returns a curried procedure. … … 75 142 ==== uni2 76 143 77 <procedure>(uni2 X Y F C) => OBJECT</procedure>144 <procedure>(uni2 X Y F C) => {{procedure}}</procedure> 78 145 79 146 Returns the result of {{(C (F X Y))}}. 80 147 81 <procedure>(uni2 F C) => PROCEDURE/2</procedure>82 <procedure>(uni2 C) => PROCEDURE/1</procedure>83 <procedure>(uni2) => PROCEDURE/1</procedure>148 <procedure>(uni2 F C) => {{procedure/2}}</procedure> 149 <procedure>(uni2 C) => {{procedure/1}}</procedure> 150 <procedure>(uni2) => {{procedure/1}}</procedure> 84 151 85 152 Returns a curried procedure. … … 87 154 ==== uni3 88 155 89 <procedure>(uni3 X Y Z F C) => OBJECT</procedure>156 <procedure>(uni3 X Y Z F C) => {{procedure}}</procedure> 90 157 91 158 Returns the result of {{(C (F X Y Z))}}. 92 159 93 <procedure>(uni3 F C) => PROCEDURE/3</procedure>94 <procedure>(uni3 C) => PROCEDURE/1</procedure>95 <procedure>(uni3) => PROCEDURE/1</procedure>160 <procedure>(uni3 F C) => {{procedure/3}}</procedure> 161 <procedure>(uni3 C) => {{procedure/1}}</procedure> 162 <procedure>(uni3) => {{procedure/1}}</procedure> 96 163 97 164 Returns a curried procedure. … … 99 166 ==== bi 100 167 101 <procedure>(bi X F G C) => OBJECT</procedure>168 <procedure>(bi X F G C) => {{procedure}}</procedure> 102 169 103 170 Returns the result of {{(C (F X) (G X))}}. 104 171 105 <procedure>(bi F G C) => PROCEDURE/1</procedure>106 <procedure>(bi F G) => PROCEDURE/1</procedure>107 <procedure>(bi C) => PROCEDURE/2</procedure>108 <procedure>(bi) => PROCEDURE/1</procedure>172 <procedure>(bi F G C) => {{procedure/1}}</procedure> 173 <procedure>(bi F G) => {{procedure/1}}</procedure> 174 <procedure>(bi C) => {{procedure/2}}</procedure> 175 <procedure>(bi) => {{procedure/1}}</procedure> 109 176 110 177 Returns a curried procedure. … … 112 179 ==== bi2 113 180 114 <procedure>(bi2 X Y F G C) => OBJECT</procedure>181 <procedure>(bi2 X Y F G C) => {{procedure}}</procedure> 115 182 116 183 Returns the result of {{(C (F X Y) (G X Y))}}. 117 184 118 <procedure>(bi2 F G C) => PROCEDURE/2</procedure>119 <procedure>(bi2 F G) => PROCEDURE/1</procedure>120 <procedure>(bi2 C) => PROCEDURE/2</procedure>121 <procedure>(bi2) => PROCEDURE/1</procedure>185 <procedure>(bi2 F G C) => {{procedure/2}}</procedure> 186 <procedure>(bi2 F G) => {{procedure/1}}</procedure> 187 <procedure>(bi2 C) => {{procedure/2}}</procedure> 188 <procedure>(bi2) => {{procedure/1}}</procedure> 122 189 123 190 Returns a curried procedure. … … 125 192 ==== bi3 126 193 127 <procedure>(bi3 X Y Z F G C) => OBJECT</procedure>194 <procedure>(bi3 X Y Z F G C) => {{procedure}}</procedure> 128 195 129 196 Returns the result of {{(C (F X Y Z) (G X Y Z))}}. 130 197 131 <procedure>(bi3 F G C) => PROCEDURE/3</procedure>132 <procedure>(bi3 F G) => PROCEDURE/1</procedure>133 <procedure>(bi3 C) => PROCEDURE/2</procedure>134 <procedure>(bi3) => PROCEDURE/1</procedure>198 <procedure>(bi3 F G C) => {{procedure/3}}</procedure> 199 <procedure>(bi3 F G) => {{procedure/1}}</procedure> 200 <procedure>(bi3 C) => {{procedure/2}}</procedure> 201 <procedure>(bi3) => {{procedure/1}}</procedure> 135 202 136 203 Returns a curried procedure. … … 138 205 ==== bi@ 139 206 140 <procedure>(bi@ X Y F C) => OBJECT</procedure>207 <procedure>(bi@ X Y F C) => {{procedure}}</procedure> 141 208 142 209 Returns the result of {{(C (F X) (F Y))}}. 143 210 144 <procedure>(bi@ F C) => PROCEDURE/2</procedure>211 <procedure>(bi@ F C) => {{procedure/2}}</procedure> 145 212 146 213 Returns a curried procedure. … … 148 215 ==== tri 149 216 150 <procedure>(tri X F G H C) => OBJECT</procedure>217 <procedure>(tri X F G H C) => {{procedure}}</procedure> 151 218 152 219 Returns the result of {{(C (F X) (G X) (H X))}}. 153 220 154 <procedure>(tri F G H C) => PROCEDURE/1</procedure>155 <procedure>(tri F G H) => PROCEDURE/1</procedure>156 <procedure>(tri C) => PROCEDURE/3</procedure>157 <procedure>(tri) => PROCEDURE/1</procedure>221 <procedure>(tri F G H C) => {{procedure/1}}</procedure> 222 <procedure>(tri F G H) => {{procedure/1}}</procedure> 223 <procedure>(tri C) => {{procedure/3}}</procedure> 224 <procedure>(tri) => {{procedure/1}}</procedure> 158 225 159 226 Returns a curried procedure. … … 161 228 ==== tri2 162 229 163 <procedure>(tri2 X Y F G H C) => OBJECT</procedure>230 <procedure>(tri2 X Y F G H C) => {{procedure}}</procedure> 164 231 165 232 Returns the result of {{(C (F X Y) (G X Y) (H X Y))}}. 166 233 167 <procedure>(tri2 F G H C) => PROCEDURE/2</procedure>168 <procedure>(tri2 F G H) => PROCEDURE/1</procedure>169 <procedure>(tri2 C) => PROCEDURE/3</procedure>170 <procedure>(tri2) => PROCEDURE/1</procedure>234 <procedure>(tri2 F G H C) => {{procedure/2}}</procedure> 235 <procedure>(tri2 F G H) => {{procedure/1}}</procedure> 236 <procedure>(tri2 C) => {{procedure/3}}</procedure> 237 <procedure>(tri2) => {{procedure/1}}</procedure> 171 238 172 239 Returns a curried procedure. … … 174 241 ==== tri3 175 242 176 <procedure>(tri3 X Y Z F G H C) => OBJECT</procedure>243 <procedure>(tri3 X Y Z F G H C) => {{procedure}}</procedure> 177 244 178 245 Returns the result of {{(C (F X Y Z) (G X Y Z) (H X Y Z))}}. 179 246 180 <procedure>(tri3 F G H C) => PROCEDURE/3</procedure>181 <procedure>(tri3 F G H) => PROCEDURE/1</procedure>182 <procedure>(tri3 C) => PROCEDURE/3</procedure>183 <procedure>(tri3) => PROCEDURE/1</procedure>247 <procedure>(tri3 F G H C) => {{procedure/3}}</procedure> 248 <procedure>(tri3 F G H) => {{procedure/1}}</procedure> 249 <procedure>(tri3 C) => {{procedure/3}}</procedure> 250 <procedure>(tri3) => {{procedure/1}}</procedure> 184 251 185 252 Returns a curried procedure. … … 187 254 ==== tri@ 188 255 189 <procedure>(tri@ X Y Z F G H C) => OBJECT</procedure>256 <procedure>(tri@ X Y Z F G H C) => {{procedure}}</procedure> 190 257 191 258 Returns the result of {{(C (F X) (G Y) (H Z))}}. 192 259 193 <procedure>(tri@ F G H C) => PROCEDURE/3</procedure>260 <procedure>(tri@ F G H C) => {{procedure/3}}</procedure> 194 261 195 262 Returns a curried procedure. … … 197 264 ==== dip 198 265 199 <procedure>(dip X Y F C) => OBJECT</procedure>266 <procedure>(dip X Y F C) => {{procedure}}</procedure> 200 267 201 268 Returns the result of {{(C (F X) Y)}}. 202 269 203 <procedure>(dip F C) => PROCEDURE/2</procedure>270 <procedure>(dip F C) => {{procedure/2}}</procedure> 204 271 205 272 Returns a curried procedure. … … 207 274 ==== dup 208 275 209 <procedure>(dup X C) => OBJECT</procedure>276 <procedure>(dup X C) => {{procedure}}</procedure> 210 277 211 278 Returns the result of {{(C X X)}}. 212 279 213 <procedure>(dup C) => PROCEDURE/1</procedure>280 <procedure>(dup C) => {{procedure/1}}</procedure> 214 281 215 282 Returns a curried procedure. … … 217 284 ==== dupd 218 285 219 <procedure>(dupd X Y C) => OBJECT</procedure>286 <procedure>(dupd X Y C) => {{procedure}}</procedure> 220 287 221 288 Returns the result of {{(C X X Y)}}. 222 289 223 <procedure>(dupd C) => PROCEDURE/2</procedure>290 <procedure>(dupd C) => {{procedure/2}}</procedure> 224 291 225 292 Returns a curried procedure. … … 227 294 ==== swap 228 295 229 <procedure>(swap X Y C) => OBJECT</procedure>296 <procedure>(swap X Y C) => {{procedure}}</procedure> 230 297 231 298 Returns the result of {{(C Y X)}}. 232 299 233 <procedure>(swap C) => PROCEDURE/2</procedure>300 <procedure>(swap C) => {{procedure/2}}</procedure> 234 301 235 302 Returns a curried procedure. … … 237 304 ==== drop 238 305 239 <procedure>(drop X C)< => OBJECT/procedure>306 <procedure>(drop X C)< => {{procedure}}/procedure> 240 307 241 308 Returns the result of {{(C)}}. 242 309 243 <procedure>(drop C) => PROCEDURE/1</procedure>310 <procedure>(drop C) => {{procedure/1}}</procedure> 244 311 245 312 Returns a curried procedure. … … 247 314 ==== drop/2 248 315 249 <procedure>(drop/2 X Y C) => OBJECT</procedure>316 <procedure>(drop/2 X Y C) => {{procedure}}</procedure> 250 317 251 318 Returns the result of {{(C X)}}. 252 319 253 <procedure>(drop/2 C) => PROCEDURE/2</procedure> 254 255 Returns a curried procedure. 256 257 258 == Usage 259 260 <enscript language=scheme> 261 (requireextension logicalcombinators) 262 </enscript> 263 264 <enscript language=scheme> 265 (requirelibrary logicalcombinators) 266 ... 267 (import logicalcombinators) 268 </enscript> 269 270 271 == Examples 272 273 <enscript highlight=scheme> 274 (group/key identity '(1 2 3 3 4 4 4)) ;=> ((1) (2) (3 3) (4 4 4)) 275 276 (group/key car '((a 1) (a 2) (b 1))) ;=> '(((a 1) (a 2)) ((b 1))) 277 278 (sort '(("a" . 1) ("z" . 3) ("b" . 2)) (makelessthan/key first stringci<?)) ;=> (("a" . 1) ("b" . 2) ("z" . 3)) 279 </enscript> 320 <procedure>(drop/2 C) => {{procedure/2}}</procedure> 321 322 Returns a curried procedure. 280 323 281 324 … … 284 327 * Inspired by email conversations with Graham Fawcett in Feb '08. 285 328 286 287 == Requirements 288 289 290 == Bugs and Limitations 329 * The {{leftsection}} and {{rightsection}} are from Chicken core 330 {{datastructures}}. 291 331 292 332 … … 298 338 == Version history 299 339 340 ; 1.1.0 : Added {{sectioncombinators}}. 300 341 ; 1.0.0 : Chicken 4 release. 301 342
Note: See TracChangeset
for help on using the changeset viewer.