Changeset 18915 in project


Ignore:
Timestamp:
07/21/10 20:38:41 (10 years ago)
Author:
Kon Lovett
Message:

Rel 1.1.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/combinators

    r14119 r18915  
    1010== Documentation
    1111
     12=== Section Combinators
     13
     14==== Usage
     15
     16<enscript language=scheme>
     17(require-extension section-combinators)
     18</enscript>
     19
     20==== left-section
     21
     22<procedure>(left-section FUNC ARG0 ...) => {{procedure}}</procedure>
     23
     24Returns 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
     30Returns a partially curried procedure.
     31
     32==== right-section
     33
     34<procedure>(right-section FUNC ARG0 ...) => {{procedure}}</procedure>
     35
     36Returns 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
     42Returns a partially curried procedure.
     43
    1244
    1345=== Sort Combinators
    1446
     47==== Usage
     48
     49<enscript language=scheme>
     50(require-extension sort-combinators)
     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)) (make-less-than/key first string-ci<?)) ;=> (("a" . 1) ("b" . 2) ("z" . 3))
     61</enscript>
     62
    1563==== group/key
    1664
    17 <procedure>(group/key KEYPROC LYST [EQUALITY equal?])</procedure>
     65<procedure>(group/key FUNC LYST [EQUALITY equal?])</procedure>
    1866
    1967Groups a {{LYST}} of elements by some key attribute. Uses the single-argument
    20 {{KEYPROC}} to retrieve key values & the {{EQUALITY}} procedure to compare
     68{{FUNC}} to retrieve key values & the {{EQUALITY}} function to compare
    2169them.
    2270
     71The {{LYST}} must be in sorted order with respect to the key!
     72
    2373Returns a list of grouped elements.
    2474
    2575==== make-less-than/key
    2676
    27 <procedure>(make-less-than/key KEYPROC [LESS-THAN <])</procedure>
    28 
    29 Returns a two-argument procedure that uses the single-argument {{KEYPROC}} to
     77<procedure>(make-less-than/key FUNC [LESS-THAN <]) => {{procedure/2}}</procedure>
     78
     79Returns a two-argument procedure that uses the single-argument {{FUNC}} to
    3080retrieve key values & the two-argument {{LESS-THAN}} procedure to compare them.
    3181
    3282==== make-equal/key
    3383
    34 <procedure>(make-equal/key KEYPROC [EQUAL =])</procedure>
    35 
    36 Returns a two-argument procedure that uses the single-argument {{KEYPROC}} to
     84<procedure>(make-equal/key FUNC [EQUAL =]) => {{procedure/2}}</procedure>
     85
     86Returns a two-argument procedure that uses the single-argument {{FUNC}} to
    3787retrieve key values & the two-argument {{EQUAL}} procedure to compare them.
    3888
     
    4090=== Logical Combinators
    4191
     92==== Usage
     93
     94<enscript language=scheme>
     95(require-extension logical-combinators)
     96</enscript>
     97
    4298==== andf
    4399
    44100<procedure>(andf OBJECT...)</procedure>
     101
     102Eager version of {{and}}.
    45103
    46104Returns last {{(not #f)}} {{OBJECT}} when all {{OBJECT...}} are {{(not #f)}},
     
    51109<procedure>(orf OBJECT...)</procedure>
    52110
     111Eager version of {{or}}.
     112
    53113Returns first {{(not #f)}} {{OBJECT}}, {{#f}} otherwise.
    54114
     115
    55116=== Stack Combinators
    56117
     118==== Usage
     119
     120<enscript language=scheme>
     121(require-extension stack-combinators)
     122</enscript>
     123
    57124{{C}} is a combinator {{function}}.
    58125
     
    63130==== uni
    64131
    65 <procedure>(uni X F C) => OBJECT</procedure>
     132<procedure>(uni X F C) => {{procedure}}</procedure>
    66133
    67134Returns the result of {{(C (F X))}}.
    68135
    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>
    72139
    73140Returns a curried procedure.
     
    75142==== uni2
    76143
    77 <procedure>(uni2 X Y F C) => OBJECT</procedure>
     144<procedure>(uni2 X Y F C) => {{procedure}}</procedure>
    78145
    79146Returns the result of {{(C (F X Y))}}.
    80147
    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>
    84151
    85152Returns a curried procedure.
     
    87154==== uni3
    88155
    89 <procedure>(uni3 X Y Z F C) => OBJECT</procedure>
     156<procedure>(uni3 X Y Z F C) => {{procedure}}</procedure>
    90157
    91158Returns the result of {{(C (F X Y Z))}}.
    92159
    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>
    96163
    97164Returns a curried procedure.
     
    99166==== bi
    100167
    101 <procedure>(bi X F G C) => OBJECT</procedure>
     168<procedure>(bi X F G C) => {{procedure}}</procedure>
    102169
    103170Returns the result of {{(C (F X) (G X))}}.
    104171
    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>
    109176
    110177Returns a curried procedure.
     
    112179==== bi2
    113180
    114 <procedure>(bi2 X Y F G C) => OBJECT</procedure>
     181<procedure>(bi2 X Y F G C) => {{procedure}}</procedure>
    115182
    116183Returns the result of {{(C (F X Y) (G X Y))}}.
    117184
    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>
    122189
    123190Returns a curried procedure.
     
    125192==== bi3
    126193
    127 <procedure>(bi3 X Y Z F G C) => OBJECT</procedure>
     194<procedure>(bi3 X Y Z F G C) => {{procedure}}</procedure>
    128195
    129196Returns the result of {{(C (F X Y Z) (G X Y Z))}}.
    130197
    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>
    135202
    136203Returns a curried procedure.
     
    138205==== bi@
    139206
    140 <procedure>(bi@ X Y F C) => OBJECT</procedure>
     207<procedure>(bi@ X Y F C) => {{procedure}}</procedure>
    141208
    142209Returns the result of {{(C (F X) (F Y))}}.
    143210
    144 <procedure>(bi@ F C) => PROCEDURE/2</procedure>
     211<procedure>(bi@ F C) => {{procedure/2}}</procedure>
    145212
    146213Returns a curried procedure.
     
    148215==== tri
    149216
    150 <procedure>(tri X F G H C) => OBJECT</procedure>
     217<procedure>(tri X F G H C) => {{procedure}}</procedure>
    151218
    152219Returns the result of {{(C (F X) (G X) (H X))}}.
    153220
    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>
    158225
    159226Returns a curried procedure.
     
    161228==== tri2
    162229
    163 <procedure>(tri2 X Y F G H C) => OBJECT</procedure>
     230<procedure>(tri2 X Y F G H C) => {{procedure}}</procedure>
    164231
    165232Returns the result of {{(C (F X Y) (G X Y) (H X Y))}}.
    166233
    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>
    171238
    172239Returns a curried procedure.
     
    174241==== tri3
    175242
    176 <procedure>(tri3 X Y Z F G H C) => OBJECT</procedure>
     243<procedure>(tri3 X Y Z F G H C) => {{procedure}}</procedure>
    177244
    178245Returns the result of {{(C (F X Y Z) (G X Y Z) (H X Y Z))}}.
    179246
    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>
    184251
    185252Returns a curried procedure.
     
    187254==== tri@
    188255
    189 <procedure>(tri@ X Y Z F G H C) => OBJECT</procedure>
     256<procedure>(tri@ X Y Z F G H C) => {{procedure}}</procedure>
    190257
    191258Returns the result of {{(C (F X) (G Y) (H Z))}}.
    192259
    193 <procedure>(tri@ F G H C) => PROCEDURE/3</procedure>
     260<procedure>(tri@ F G H C) => {{procedure/3}}</procedure>
    194261
    195262Returns a curried procedure.
     
    197264==== dip
    198265
    199 <procedure>(dip X Y F C) => OBJECT</procedure>
     266<procedure>(dip X Y F C) => {{procedure}}</procedure>
    200267
    201268Returns the result of {{(C (F X) Y)}}.
    202269
    203 <procedure>(dip F C) => PROCEDURE/2</procedure>
     270<procedure>(dip F C) => {{procedure/2}}</procedure>
    204271
    205272Returns a curried procedure.
     
    207274==== dup
    208275
    209 <procedure>(dup X C) => OBJECT</procedure>
     276<procedure>(dup X C) => {{procedure}}</procedure>
    210277
    211278Returns the result of {{(C X X)}}.
    212279
    213 <procedure>(dup C) => PROCEDURE/1</procedure>
     280<procedure>(dup C) => {{procedure/1}}</procedure>
    214281
    215282Returns a curried procedure.
     
    217284==== dupd
    218285
    219 <procedure>(dupd X Y C) => OBJECT</procedure>
     286<procedure>(dupd X Y C) => {{procedure}}</procedure>
    220287
    221288Returns the result of {{(C X X Y)}}.
    222289
    223 <procedure>(dupd C) => PROCEDURE/2</procedure>
     290<procedure>(dupd C) => {{procedure/2}}</procedure>
    224291
    225292Returns a curried procedure.
     
    227294==== swap
    228295
    229 <procedure>(swap X Y C) => OBJECT</procedure>
     296<procedure>(swap X Y C) => {{procedure}}</procedure>
    230297
    231298Returns the result of {{(C Y X)}}.
    232299
    233 <procedure>(swap C) => PROCEDURE/2</procedure>
     300<procedure>(swap C) => {{procedure/2}}</procedure>
    234301
    235302Returns a curried procedure.
     
    237304==== drop
    238305
    239 <procedure>(drop X C)< => OBJECT/procedure>
     306<procedure>(drop X C)< => {{procedure}}/procedure>
    240307
    241308Returns the result of {{(C)}}.
    242309
    243 <procedure>(drop C) => PROCEDURE/1</procedure>
     310<procedure>(drop C) => {{procedure/1}}</procedure>
    244311
    245312Returns a curried procedure.
     
    247314==== drop/2
    248315
    249 <procedure>(drop/2 X Y C) => OBJECT</procedure>
     316<procedure>(drop/2 X Y C) => {{procedure}}</procedure>
    250317
    251318Returns the result of {{(C X)}}.
    252319
    253 <procedure>(drop/2 C) => PROCEDURE/2</procedure>
    254 
    255 Returns a curried procedure.
    256 
    257 
    258 == Usage
    259 
    260 <enscript language=scheme>
    261 (require-extension logical-combinators)
    262 </enscript>
    263 
    264 <enscript language=scheme>
    265 (require-library logical-combinators)
    266 ...
    267 (import logical-combinators)
    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)) (make-less-than/key first string-ci<?)) ;=> (("a" . 1) ("b" . 2) ("z" . 3))
    279 </enscript>
     320<procedure>(drop/2 C) => {{procedure/2}}</procedure>
     321
     322Returns a curried procedure.
    280323
    281324
     
    284327* Inspired by e-mail conversations with Graham Fawcett in Feb '08.
    285328
    286 
    287 == Requirements
    288 
    289 
    290 == Bugs and Limitations
     329* The {{left-section}} and {{right-section}} are from Chicken core
     330{{data-structures}}.
    291331
    292332
     
    298338== Version history
    299339
     340; 1.1.0 : Added {{section-combinators}}.
    300341; 1.0.0 : Chicken 4 release.
    301342
Note: See TracChangeset for help on using the changeset viewer.