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

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

Added combinators. Updating arith.

File size: 5.0 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
67<procedure>(uni F C) => PROCEDURE/1</procedure>
68<procedure>(uni C) => PROCEDURE/1</procedure>
69<procedure>(uni) => PROCEDURE/1</procedure>
70
71==== uni2
72
73<procedure>(uni2 X Y F C) => OBJECT</procedure>
74
75<procedure>(uni2 F C) => PROCEDURE/2</procedure>
76<procedure>(uni2 C) => PROCEDURE/1</procedure>
77<procedure>(uni2) => PROCEDURE/1</procedure>
78
79==== uni3
80
81<procedure>(uni3 X Y Z F C) => OBJECT</procedure>
82
83<procedure>(uni3 F C) => PROCEDURE/3</procedure>
84<procedure>(uni3 C) => PROCEDURE/1</procedure>
85<procedure>(uni3) => PROCEDURE/1</procedure>
86
87==== uni@
88
89<procedure>(uni@ X F C) => OBJECT</procedure>
90
91<procedure>(uni@ F C) => PROCEDURE/1</procedure>
92
93==== bi
94
95<procedure>(bi X F G C) => OBJECT</procedure>
96
97<procedure>(bi F G C) => PROCEDURE/1</procedure>
98<procedure>(bi F G) => PROCEDURE/1</procedure>
99<procedure>(bi C) => PROCEDURE/2</procedure>
100<procedure>(bi) => PROCEDURE/1</procedure>
101
102==== bi2
103
104<procedure>(bi2 X Y F G C) => OBJECT</procedure>
105
106<procedure>(bi2 F G C) => PROCEDURE/2</procedure>
107<procedure>(bi2 F G) => PROCEDURE/1</procedure>
108<procedure>(bi2 C) => PROCEDURE/2</procedure>
109<procedure>(bi2) => PROCEDURE/1</procedure>
110
111==== bi3
112
113<procedure>(bi3 X Y Z F G C) => OBJECT</procedure>
114
115<procedure>(bi3 F G C) => PROCEDURE/3</procedure>
116<procedure>(bi3 F G) => PROCEDURE/1</procedure>
117<procedure>(bi3 C) => PROCEDURE/2</procedure>
118<procedure>(bi3) => PROCEDURE/1</procedure>
119
120==== bi@
121
122<procedure>(bi@ X Y F C) => OBJECT</procedure>
123
124<procedure>(bi@ F C) => PROCEDURE/2</procedure>
125
126==== tri
127
128<procedure>(tri X F G H C) => OBJECT</procedure>
129
130<procedure>(tri F G H C) => PROCEDURE/1</procedure>
131<procedure>(tri F G H) => PROCEDURE/1</procedure>
132<procedure>(tri C) => PROCEDURE/3</procedure>
133<procedure>(tri) => PROCEDURE/1</procedure>
134
135==== tri2
136
137<procedure>(tri2 X Y F G H C) => OBJECT</procedure>
138
139<procedure>(tri2 F G H C) => PROCEDURE/2</procedure>
140<procedure>(tri2 F G H) => PROCEDURE/1</procedure>
141<procedure>(tri2 C) => PROCEDURE/3</procedure>
142<procedure>(tri2) => PROCEDURE/1</procedure>
143
144==== tri3
145
146<procedure>(tri3 X Y Z F G H C) => OBJECT</procedure>
147
148<procedure>(tri3 F G H C) => PROCEDURE/3</procedure>
149<procedure>(tri3 F G H) => PROCEDURE/1</procedure>
150<procedure>(tri3 C) => PROCEDURE/3</procedure>
151<procedure>(tri3) => PROCEDURE/1</procedure>
152
153==== tri@
154
155<procedure>(tri@ X Y Z F G H C) => OBJECT</procedure>
156
157<procedure>(tri@ F G H C) => PROCEDURE/3</procedure>
158
159==== dip
160
161<procedure>(dip X Y F C) => OBJECT</procedure>
162
163<procedure>(dip F C) => PROCEDURE/2</procedure>
164
165==== dup
166
167<procedure>(dup X C) => OBJECT</procedure>
168
169<procedure>(dup C) => PROCEDURE/1</procedure>
170
171==== dupd
172
173<procedure>(dupd X Y C) => OBJECT</procedure>
174
175<procedure>(dupd C) => PROCEDURE/2</procedure>
176
177==== swap
178
179<procedure>(swap X Y C) => OBJECT</procedure>
180
181<procedure>(swap C) => PROCEDURE/2</procedure>
182
183==== drop
184
185<procedure>(drop X C)< => OBJECT/procedure>
186
187<procedure>(drop C) => PROCEDURE/1</procedure>
188
189==== drop/2
190
191<procedure>(drop/2 X Y C) => OBJECT</procedure>
192
193<procedure>(drop/2 C) => PROCEDURE/2</procedure>
194
195
196== Usage
197
198<enscript language=scheme>
199(require-extension logical-combinators)
200</enscript>
201
202<enscript language=scheme>
203(require-library logical-combinators)
204...
205(import logical-combinators)
206</enscript>
207
208
209== Examples
210
211<enscript highlight=scheme>
212(group/key identity '(1 2 3 3 4 4 4)) ;=> ((1) (2) (3 3) (4 4 4))
213
214(group/key car '((a 1) (a 2) (b 1)))  ;=> '(((a 1) (a 2)) ((b 1)))
215
216(sort '(("a" . 1) ("z" . 3) ("b" . 2)) (make-less-than/key first string-ci<?)) ;=> (("a" . 1) ("b" . 2) ("z" . 3))
217</enscript>
218
219
220== Notes
221
222* Inspired by e-mail conversations with Graham Fawcett in Feb '08.
223
224
225== Requirements
226
227
228== Bugs and Limitations
229
230
231== Author
232
233[[kon lovett]]
234
235
236== Version history
237
238; 1.0.0 : Chicken 4 release.
239
240
241== License
242
243Public Domain.
Note: See TracBrowser for help on using the repository browser.