comparison extendlib.rhope @ 0:76568becd6d6

Rhope Alpha 2a source import
author Mike Pavone <pavone@retrodev.com>
date Tue, 28 Apr 2009 23:06:07 +0000
parents
children b3f71490858c
comparison
equal deleted inserted replaced
-1:000000000000 0:76568becd6d6
1
2 Val[in:out]
3 {
4 out <- in
5 }
6
7 _Map[list,index,worker:out]
8 {
9 newval <- [
10 [worker]Do[
11 [()]Append[ [list]Index[index] ]
12 ]
13 ]Index[0]
14
15 [list]Next[index]
16 {
17 out <- [_Map[list, ~, worker]]Set[index, newval]
18 }{
19 out <- [list]Set[index, newval]
20 }
21 }
22
23 Map[list,worker:out]
24 {
25 [list]First
26 {
27 out <- _Map[list, ~, worker]
28 }{
29 out <- list
30 }
31 }
32
33 _Key Value Map[list,index,newlist,worker:out]
34 {
35 [worker]Do[
36 [[()]Append[ [list]Index[index] ]]Append[index]
37 ]
38 {
39 newval <- [~]Index[0]
40 newkey <- [~]Index[1]
41 }
42
43 next <- [newlist]Set[newkey, newval]
44
45 [list]Next[index]
46 {
47 out <- _Key Value Map[list, ~, next, worker]
48 }{
49 out <- Val[next]
50 }
51 }
52
53 New Like@List[in:out]
54 {
55 out <- ()
56 }
57
58 New Like@Dictionary[in:out]
59 {
60 out <- New@Dictionary[]
61 }
62
63 Key Value Map[list,worker:out]
64 {
65 [list]First
66 {
67 out <- _Key Value Map[list, ~, New Like[list], worker]
68 }{
69 out <- New Like[list]
70 }
71 }
72
73 In[needle,haystack:found?]
74 {
75 [haystack]Get DString[needle]
76 {
77 found? <- Yes
78 } {} {} {
79 found? <- No
80 }
81 }
82
83 Left Trim[string,trim:trimmed]
84 {
85 If[ [[string]Length] > [0] ]
86 {
87 first,rest <- [string]Slice[1]
88 If[ [first]In[trim] ]
89 {
90 trimmed <- Left Trim[rest, trim]
91 }{
92 trimmed <- string
93 }
94 }{
95 trimmed <- string
96 }
97 }
98
99 Right Trim[string,trim:trimmed]
100 {
101 If[ [[string]Length] > [0] ]
102 {
103 rest,last <- [string]Slice[ [[string]Length] - [1]]
104 If[ [last]In[trim] ]
105 {
106 trimmed <- Right Trim[rest, trim]
107 }{
108 trimmed <- string
109 }
110 }{
111 trimmed <- string
112 }
113 }
114
115 Trim[string,trim:trimmed]
116 {
117 left <- Left Trim[string, trim]
118 trimmed <- Right Trim[left, trim]
119 }
120
121 Max[a,b:max]
122 {
123 If[[a] > [b]]
124 {
125 max <- a
126 }{
127 max <- b
128 }
129 }
130
131 Count Substring[string,substring:out]
132 {
133 out <- Max[[[[string]Split[substring]]Length] - [1], 0]
134 }
135
136 _Key Value Join[dict,key,key sep,val sep,string:out]
137 {
138 new string <- [[[string]Append[key]]Append[key sep]]Append[ [dict]Index[key] ]
139 [dict]Next[key]
140 {
141 out <- _Key Value Join[dict, ~, key sep, val sep, [new string]Append[val sep]]
142 }{
143 out <- Val[new string]
144 }
145 }
146
147 Key Value Join[dict,key sep,val sep:out]
148 {
149 [dict]First
150 {
151 out <- _Key Value Join[dict, ~, key sep, val sep, ""]
152 }{
153 out <- ""
154 }
155 }
156
157 _Combine[source,dest,key:out]
158 {
159 new dest <- [dest]Set[key, [source]Index[key]]
160 [source]Next[key]
161 {
162 out <- _Combine[source, new dest, ~]
163 }{
164 out <- Val[new dest]
165 }
166 }
167
168 Combine[source,dest:out]
169 {
170 [source]First
171 {
172 out <- _Combine[source, dest, ~]
173 }{
174 out <- dest
175 }
176 }
177
178 _Fold[list,index,current,worker:out]
179 {
180 newval <- [
181 [worker]Do[
182 [[[()]Append[ current ]]Append[ [list]Index[index] ]]Append[index]
183 ]
184 ]Index[0]
185
186 [list]Next[index]
187 {
188 out <- _Fold[list, ~, newval, worker]
189 }{
190 out <- Val[newval]
191 }
192 }
193
194 Fold[worker,start,list:out]
195 {
196 [list]First
197 {
198 out <- _Fold[list, ~, start, worker]
199 }{
200 out <- start
201 }
202 }
203
204 _Dict Split[dict,entry,index,keydelim:out]
205 {
206 parts <- [entry]Split[keydelim]
207 out <- [dict]Set[[parts]Index[0],[parts]Index[1]]
208 }
209
210 Dict Split[string,keydelim,entrydelim:out]
211 {
212 out <- Fold[["_Dict Split"]Set Input[3, keydelim], New@Dictionary[], [string]Split[entrydelim]]
213 }
214
215 Previous@List[list,index:prev index,not found]
216 {
217 prev <- [index] - [1]
218 If[[prev] < [0]]
219 {
220 not found <- list
221 }{
222 [list]Index[prev]
223 {
224 prev index <- Val[prev]
225 }{
226 prev index, not found <- [list]Previous[prev]
227 }
228 }
229 }
230
231 Last@List[list:out,not found]
232 {
233 out, not found <- [list]Previous[[list]Length]
234 }
235
236 _Reverse Fold[list,index,start,worker:out]
237 {
238 newval <- [
239 [worker]Do[
240 [[[()]Append[ start ]]Append[ [list]Index[index] ]]Append[index]
241 ]
242 ]Index[0]
243
244 [list]Previous[index]
245 {
246 out <- _Reverse Fold[list, ~, newval, worker]
247 }{
248 out <- Val[newval]
249 }
250 }
251
252 Reverse Fold[worker,start,list:out]
253 {
254 [list]Last
255 {
256 out <- _Reverse Fold[list, ~, start, worker]
257 }{
258 out <- list
259 }
260 }
261
262 _Join[list,delim,current,index:out]
263 {
264 [list]Next[index]
265 {
266 out <- _Join[list, delim, [[current]Append[delim]]Append[[list]Index[~]], ~]
267 }{
268 out <- current
269 }
270 }
271
272 Join[list,delim:out]
273 {
274 [list]First
275 {
276 out <- _Join[list, delim, [list]Index[~], ~]
277 }{
278 out <- ""
279 }
280 }
281
282 Replace[string,find,replace:replaced]
283 {
284 replaced <- [[string]Split[find]]Join[replace]
285 }
286
287 Concatenate[left,right:out]
288 {
289 out <- Fold[["Append"]<String@Worker, left, right]
290 }
291
292 Starts With[thing,starts with:out]
293 {
294 out <- [[thing]Slice[[starts with]Length]] = [starts with]
295 }
296
297 Ends With[thing,ends with:out]
298 {
299 ,compare <- [thing]Slice[ [[thing]Length] - [[ends with]Length] ]
300 out <- [compare] = [ends with]
301 }
302
303 As List@String[string:list]
304 {
305 list <- [()]Append[string]
306 }
307
308 As List@List[in:out]
309 {
310 out <- in
311 }
312
313 _Filter[list,index,worker,destlist:out]
314 {
315 filter? <- [
316 [worker]Do[
317 [()]Append[ [list]Index[index] ]
318 ]
319 ]Index[0]
320 If[filter?]
321 {
322 newlist <- [destlist]Append[[list]Index[index]]
323 }{
324 newlist <- destlist
325 }
326
327 [list]Next[index]
328 {
329 out <- _Filter[list, ~, worker, newlist]
330 }{
331 out <- Val[newlist]
332 }
333 }
334
335 Filter[list,worker:out]
336 {
337 [list]First
338 {
339 out <- _Filter[list, ~, worker, ()]
340 }{
341 out <- list
342 }
343 }
344
345 Pop@List[list:out]
346 {
347 [list]Last
348 {
349 out <- [list]Remove[~]
350 }{
351 out <- list
352 }
353 }
354
355 Peek@List[list:out,empty]
356 {
357 [list]Last
358 {
359 out <- [list]Index[~]
360 }{
361 empty <- list
362 }
363 }
364
365 Contains[haystack,needle:out]
366 {
367 [haystack]Get DString[needle]
368 {
369 out <- Yes
370 } {} {} {
371 out <- No
372 }
373 }
374
375 _Find[haystack,needle,index:outindex,notfound]
376 {
377 If[[[haystack]Index[index]] = [needle]]
378 {
379 outindex <- index
380 }{
381 [haystack]Next[index]
382 {
383 outindex,notfound <- _Find[haystack,needle,~]
384 }{
385 notfound <- needle
386 }
387 }
388 }
389
390 Find[haystack,needle:index,not found]
391 {
392 [haystack]First
393 {
394 index,not found <- _Find[haystack, needle, ~]
395 }{
396 not found <- needle
397 }
398
399 }
400
401 Get Pretty Print Value[value:print,index,print indent,done,out value]
402 {
403 If[[Type Of[value]] = ["List"]]
404 {
405 out value <- value
406 list <- value
407 object <- value
408 }{
409 If[[Type Of[value]] = ["Dictionary"]]
410 {
411 out value <- value
412 list <- value
413 object <- value
414 }{
415 If[[Type Of[value]] = ["String"]]
416 {
417 out value <- value
418 print <- value
419 done <- 1
420 }{
421 If[[Type Of[value]] = ["Whole Number"]]
422 {
423 out value <- value
424 print <- value
425 done <- 1
426 }{
427 If[[Type Of[value]] = ["Yes No"]]
428 {
429 out value <- value
430 print <- value
431 done <- 1
432 }{
433 If[[Type Of[value]] = ["Real Number"]]
434 {
435 out value <- value
436 print <- value
437 done <- 1
438 }{
439 object <- value
440 fieldlist <- [Blueprint Of[value]]Get Fields
441 [fieldlist]First
442 {
443 list <- _Object to Dict[value, fieldlist, ~, New@Dictionary[]]
444 out value <- Val[list]
445 }{
446 out value <- value
447 done <- 1
448 }
449 }
450 }
451 }
452 }
453
454 }
455 }
456 print <- Type Of[object]
457 index <- [list]First {}
458 {
459 print indent <- "{Empty}"
460 }
461
462 }
463
464 Pretty Print Helper[list,tabs,index:out]
465 {
466 newtabs <- [tabs]Append[" "]
467 print,new index,indented,done,value <- Get Pretty Print Value[[list]Index[index]]
468 Print[ [[[tabs]Append[index]]Append[": "]]Append[print] ]
469 {
470 done <- Pretty Print Helper[value,newtabs ,new index]
471 done <- Print[[newtabs]Append[indented]]
472
473 Val[done]
474 {
475 [list]Next[index]
476 {
477 out <- Pretty Print Helper[list, tabs, ~]
478 }{
479 out <- 1
480 }
481 }
482 }
483
484 }
485
486 Pretty Print[toprint,tabs:out]
487 {
488 newtabs <- [tabs]Append[" "]
489 ,index,indented,,value <- Get Pretty Print Value[toprint]
490 {
491 Print[[tabs]Append[~]]
492 {
493 Pretty Print Helper[value,newtabs ,index]
494 Print[[newtabs]Append[indented]]
495 }
496 }
497 out <- 1
498 }
499
500 _Object to Dict[object,field list,index,dict:out]
501 {
502 field <- [field list]Index[index]
503 [object]Get Field[field]
504 {
505 nextdict <- [dict]Set[field, ~]
506 }{
507 nextdict <- dict
508 }
509 [field list]Next[index]
510 {
511 out <- _Object to Dict[object, field list, ~, nextdict]
512 }{
513 out <- Val[nextdict]
514 }
515 }
516
517 _Keys[list,val,key:out]
518 {
519 out <- [list]Append[key]
520 }
521
522 Keys[container:out]
523 {
524 out <- Fold["_Keys", New@List[], container]
525 }
526