source: project/wiki/eggref/4/combinators @ 14019

Last change on this file since 14019 was 14019, checked in by Kon Lovett, 12 years ago

Save.

File size: 6.1 KB
Line 
1[[tags: egg]]
2
3== combinators
4
5Combinators grab-bag.
6
7[[toc:]]
8
9
10== Documentation
11
12
13=== Sort Combinators
14
15==== group/key
16
17<procedure>(group/key KEYPROC LYST [EQUALITY equal?])</procedure>
18
19Groups a {{LYST}} of elements by some key attribute. Uses the single-argument
20{{KEYPROC}} to retrieve key values & the {{EQUALITY}} procedure to compare
21them.
22
23Returns a list of grouped elements.
24
25==== make-less-than/key
26
27<procedure>(make-less-than/key KEYPROC [LESS-THAN <])</procedure>
28
29Returns a two-argument procedure that uses the single-argument {{KEYPROC}} to
30retrieve key values & the two-argument {{LESS-THAN}} procedure to compare them.
31
32==== make-equal/key
33
34<procedure>(make-equal/key KEYPROC [EQUAL =])</procedure>
35
36Returns a two-argument procedure that uses the single-argument {{KEYPROC}} to
37retrieve key values & the two-argument {{EQUAL}} procedure to compare them.
38
39
40=== Logical Combinators
41
42==== andf
43
44<procedure>(andf OBJECT...)</procedure>
45
46Returns last {{(not #f)}} {{OBJECT}} when all {{OBJECT...}} are {{(not #f)}},
47{{#f}} otherwise.
48
49==== orf
50
51<procedure>(orf OBJECT...)</procedure>
52
53Returns first {{(not #f)}} {{OBJECT}}, {{#f}} otherwise.
54
55=== Stack Combinators
56
57{{C}} is a combinator {{function}}.
58
59{{F}}, {{G}} and {{H}} are {{function}}.
60
61{{X}}, {{Y}} and {{Z}} are {{object}}.
62
63==== uni
64
65<procedure>(uni X F C) => OBJECT</procedure>
66
67Returns the result of {{(C (F X))}}.
68
69<procedure>(uni F C) => PROCEDURE/1</procedure>
70<procedure>(uni C) => PROCEDURE/1</procedure>
71<procedure>(uni) => PROCEDURE/1</procedure>
72
73Returns a curried procedure.
74
75==== uni2
76
77<procedure>(uni2 X Y F C) => OBJECT</procedure>
78
79Returns the result of {{(C (F X Y))}}.
80
81<procedure>(uni2 F C) => PROCEDURE/2</procedure>
82<procedure>(uni2 C) => PROCEDURE/1</procedure>
83<procedure>(uni2) => PROCEDURE/1</procedure>
84
85Returns a curried procedure.
86
87==== uni3
88
89<procedure>(uni3 X Y Z F C) => OBJECT</procedure>
90
91Returns the result of {{(C (F X Y Z))}}.
92
93<procedure>(uni3 F C) => PROCEDURE/3</procedure>
94<procedure>(uni3 C) => PROCEDURE/1</procedure>
95<procedure>(uni3) => PROCEDURE/1</procedure>
96
97Returns a curried procedure.
98
99==== bi
100
101<procedure>(bi X F G C) => OBJECT</procedure>
102
103Returns the result of {{(C (F X) (G X))}}.
104
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>
109
110Returns a curried procedure.
111
112==== bi2
113
114<procedure>(bi2 X Y F G C) => OBJECT</procedure>
115
116Returns the result of {{(C (F X Y) (G X Y))}}.
117
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>
122
123Returns a curried procedure.
124
125==== bi3
126
127<procedure>(bi3 X Y Z F G C) => OBJECT</procedure>
128
129Returns the result of {{(C (F X Y Z) (G X Y Z))}}.
130
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>
135
136Returns a curried procedure.
137
138==== bi@
139
140<procedure>(bi@ X Y F C) => OBJECT</procedure>
141
142Returns the result of {{(C (F X) (F Y))}}.
143
144<procedure>(bi@ F C) => PROCEDURE/2</procedure>
145
146Returns a curried procedure.
147
148==== tri
149
150<procedure>(tri X F G H C) => OBJECT</procedure>
151
152Returns the result of {{(C (F X) (G X) (H X))}}.
153
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>
158
159Returns a curried procedure.
160
161==== tri2
162
163<procedure>(tri2 X Y F G H C) => OBJECT</procedure>
164
165Returns the result of {{(C (F X Y) (G X Y) (H X Y))}}.
166
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>
171
172Returns a curried procedure.
173
174==== tri3
175
176<procedure>(tri3 X Y Z F G H C) => OBJECT</procedure>
177
178Returns the result of {{(C (F X Y Z) (G X Y Z) (H X Y Z))}}.
179
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>
184
185Returns a curried procedure.
186
187==== tri@
188
189<procedure>(tri@ X Y Z F G H C) => OBJECT</procedure>
190
191Returns the result of {{(C (F X) (G Y) (H Z))}}.
192
193<procedure>(tri@ F G H C) => PROCEDURE/3</procedure>
194
195Returns a curried procedure.
196
197==== dip
198
199<procedure>(dip X Y F C) => OBJECT</procedure>
200
201Returns the result of {{(C (F X) Y)}}.
202
203<procedure>(dip F C) => PROCEDURE/2</procedure>
204
205Returns a curried procedure.
206
207==== dup
208
209<procedure>(dup X C) => OBJECT</procedure>
210
211Returns the result of {{(C X X)}}.
212
213<procedure>(dup C) => PROCEDURE/1</procedure>
214
215Returns a curried procedure.
216
217==== dupd
218
219<procedure>(dupd X Y C) => OBJECT</procedure>
220
221Returns the result of {{(C X X Y)}}.
222
223<procedure>(dupd C) => PROCEDURE/2</procedure>
224
225Returns a curried procedure.
226
227==== swap
228
229<procedure>(swap X Y C) => OBJECT</procedure>
230
231Returns the result of {{(C Y X)}}.
232
233<procedure>(swap C) => PROCEDURE/2</procedure>
234
235Returns a curried procedure.
236
237==== drop
238
239<procedure>(drop X C)< => OBJECT/procedure>
240
241Returns the result of {{(C)}}.
242
243<procedure>(drop C) => PROCEDURE/1</procedure>
244
245Returns a curried procedure.
246
247==== drop/2
248
249<procedure>(drop/2 X Y C) => OBJECT</procedure>
250
251Returns the result of {{(C X)}}.
252
253<procedure>(drop/2 C) => PROCEDURE/2</procedure>
254
255Returns 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>
280
281
282== Notes
283
284* Inspired by e-mail conversations with Graham Fawcett in Feb '08.
285
286
287== Requirements
288
289
290== Bugs and Limitations
291
292
293== Author
294
295[[kon lovett]]
296
297
298== Version history
299
300; 1.0.0 : Chicken 4 release.
301
302
303== License
304
305Public Domain.
Note: See TracBrowser for help on using the repository browser.