Mercurial > repos > rhope
comparison functional.rhope @ 84:6d41b71f1b77
Add Map, Filter and Find
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 30 Jul 2010 23:48:31 +0000 |
parents | 004f0fc8941f |
children | e73a93fb5de1 |
comparison
equal
deleted
inserted
replaced
83:27bb051d631c | 84:6d41b71f1b77 |
---|---|
19 }{ | 19 }{ |
20 out <- start | 20 out <- start |
21 } | 21 } |
22 } | 22 } |
23 | 23 |
24 _Map[list,worker,cur:out] | |
25 { | |
26 val <- [list]Index[cur] | |
27 nlist <- [list]Set[cur, [worker]Call[val, cur]] | |
28 | |
29 [nlist]Next[cur] | |
30 { | |
31 out <- _Map[nlist, worker, ~] | |
32 }{ | |
33 out <- Val[nlist] | |
34 } | |
35 } | |
36 | |
37 Map[list,worker:out] | |
38 { | |
39 [list]First | |
40 { | |
41 out <- _Map[list,worker,~] | |
42 }{ | |
43 out <- list | |
44 } | |
45 } | |
46 | |
47 _Find[list,pred,cur:loc,not found] | |
48 { | |
49 val <- [list]Index[cur] | |
50 If[[pred]Call[val]] | |
51 { | |
52 loc <- cur | |
53 }{ | |
54 ,not found <- [list]Next[cur] | |
55 { loc,not found <- _Find[list,pred,~] } | |
56 } | |
57 } | |
58 | |
59 Find[list,pred:loc,not found] | |
60 { | |
61 ,not found <- [list]First | |
62 { | |
63 loc <- _Find[list,pred,~] | |
64 } | |
65 } | |
66 | |
67 _Filter[list,pred,cur,dest:out] | |
68 { | |
69 val <- [list]Index[cur] | |
70 If[[pred]Call[val,cur]] | |
71 { | |
72 ndest <- [dest]Append[val] | |
73 }{ | |
74 ndest <- dest | |
75 } | |
76 [list]Next[cur] | |
77 { | |
78 out <- _Filter[list,pred,~,ndest] | |
79 }{ | |
80 out <- Val[ndest] | |
81 } | |
82 } | |
83 | |
84 Filter[list,pred:out] | |
85 { | |
86 [list]First | |
87 { | |
88 out <- _Filter[list,pred,~, List[]] | |
89 }{ | |
90 out <- list | |
91 } | |
92 } | |
93 |