[r6993]: sandbox / jlf / samples / pipeline / pipe_extension_test.rex  Maximize  Restore  History

Download this file

203 lines (143 with data), 7.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
call Doers.AddVisibilityFrom(.context)
call evaluate "demonstration"
--::options trace i
::routine demonstration
--- Strange... without this instruction, I don't get the first comments
nop
-- The coactivity yields two results.
-- The hello outputs are not in the pipeline flow (not displayed by the .displayer).
.coactivity~new("echo hello ; .yield[a] ; say hello ; .yield[b]")~pipe(.upper|.displayer)
-- A collection can be sorted by value (default)
.array~of(b, a, c)~pipe(.sort byValue | .displayer)
-- ...or by index
.array~of(b, a, c)~pipe(.sort byIndex | .displayer)
-- ...ascending (default)
-- The order of options is important : a value option is impacted only by the preceding options
-- This is because several value options can be specified, and a sort is made for each.
.array~of(b, a, c)~pipe(.sort ascending byValue | .displayer)
-- ...descending
.array~of(b, a, c)~pipe(.sort descending byValue | .displayer)
-- ...by index descending
-- The order of options is important : an index option is impacted only by the preceding options.
-- This is because several index options can be specified, and a sort is made for each.
.array~of(b, a, c)~pipe(.sort descending byIndex | .displayer)
-- ...caseless (stable by default)
.array~of("bb", "AA", "bB", "Aa", "Bb", "aA", "BB", "aa")~pipe(.sort caseless byValue | .displayer)
-- ...caseless quickSort (unstable)
.array~of("bb", "AA", "bB", "Aa", "Bb", "aA", "BB", "aa")~pipe(.sort caseless quickSort byValue | .displayer)
-- Sort descending with a comparator.
-- The DescendingComparator use the default CompareTo, which is made on values.
.array~of(b, a, c)~pipe(.sortWith[.DescendingComparator~new] | .displayer)
-- Sort by column with a comparator.
.array~of("c:2", "b:2", "A:2", "c:1", "a:1", "B:1", "C:3")~pipe(,
.sortWith[.InvertingComparator~new(.CaselessColumnComparator~new(3,1))] |,
.sortWith[.CaselessColumnComparator~new(1,1)] |,
.displayer,
)
-- Do something for each item (no returned value).
.array~of(1, 2, 3)~pipe(.do["say 'value='value 'index='index"] | .displayer)
-- Do something for each item (the returned result replaces the value).
.array~of(1, 2, 3)~pipe(.do["return 2*value"] | .displayer)
-- Inject a value for each item. The index of the injected value is made of two indexes.
.array~of(1, 2, 3)~pipe(.inject["value+1"] | .displayer)
-- Inject two values for each item (each item of the returned collection is written in the pipe).
.array~of(1, 2, 3)~pipe(.inject[".array~of(value+1, value+2)"] | .displayer)
-- Each injected value can be used as input to inject a new value, recursively.
-- If the recursion is infinite, must specify a limit (here 10).
.array~of(1, 2, 3)~pipe(.inject["value+1"] recursive.10 | .displayer)
-- Factorial, no value injected for -1
.array~of(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)~pipe(.inject[,
"use arg n;",
"if n < 0 then return;",
"if n == 0 then return 1;",
"return n * .context~executable~call(n - 1)"] | .displayer)
-- Select files whose name contains "rexx" in c:\program files\oorexx
.file~new("c:\program files\oorexx")~listFiles~pipe(,
.select["value~name~caselessPos('rexx') <> 0"] |,
.displayer,
)
-- Select files whose name contains "rexx" in c:\program files\oorexx, sorted by file size.
-- The "length" message is sent to the value.
.file~new("c:\program files\oorexx")~listFiles~pipe(,
.select["value~name~caselessPos('rexx') <> 0"] |,
.sortWith[.MessageComparator~new("length/N")] |,
.displayer,
)
-- Same as above, but simpler... You can sort directly by length, no need of MessageComparator
.file~new("c:\program files\oorexx")~listFiles~pipe(,
.select["value~name~caselessPos('rexx') <> 0"] |,
.sort "value~length" |,
.displayer,
)
-- Sort by file size, then by file extension (with only one .sort pipestage)
.file~new("c:\program files\oorexx")~listFiles~pipe(,
.select["value~name~caselessPos('rexx') <> 0"] |,
.sort "value~length" "filespec('e', value~name)" |,
.displayer,
)
-- All instance methods of the context.
-- Notice that the default sort by value is useless here... Must sort by index.
.context~instanceMethods~pipe(.sort byIndex | .displayer)
-- All private methods of the context.
.context~instanceMethods~pipe(,
.select["value~isPrivate"] |,
.sort byIndex |,
.displayer,
)
-- Instance methods of the specified classes (not including those inherited).
-- Each class is written in the pipeline, followed by the returned methods.
.array~of(.RexxContext, .Package, .Method)~pipe(,
.inject["value~instanceMethods(value~class)"] |,
.sort byIndex |,
.displayer,
)
-- Methods (not inherited) of all the classes whose id starts with "R".
.environment~pipe(,
.select["value~isA(.class)"] |,
.select["value~id~caselessAbbrev('R') <> 0"] |,
.inject["value~methods(value)"] |,
.sort byIndex |,
.displayer,
)
-- All packages that are visible from current context, including the current package (source of the pipeline).
-- The .displayer is not useful here (will be extended to let choose the values to display)...
.context~package~pipe(,
.inject["value~importedPackages"] recursive |,
.sort |,
.displayer,
)
-- ...In the meantime, use the .do pipeStage to display the useful values.
-- The package names are indented to highlight the dependency between packages.
-- The index is always an array.
-- Notice the circular dependency between packages (supported by inject - the recursion is stopped) :
-- extensions.cls --> doers.cls --> extensions.cls
-- This is because of Doers.AddVisibilityFrom
.context~package~pipe(,
.inject["value~importedPackages"] recursive |,
.sort |,
.do["say ' '~copies(index~items) value~name"],
)
::routine evaluate
use strict arg routineName
routine = .context~package~findRoutine(routineName)
routineSource = routine~source
clause = ""
do sourceline over routineSource
if sourceline~strip~left(3) == "---" then iterate -- Comments starting with 3 '-' are removed
else if sourceline~strip == "nop" then iterate -- nop is a workaround to get the first comments
else if sourceline~strip~left(2) == "--" then say sourceline -- Comments starting with 2 '-' are kept
else if sourceline~strip == "" then say
else do
say sourceline
if sourceline~right(1) == "," then clause ||= sourceline~left(sourceline~length - 1)
else do
clause ||= sourceline
interpret clause
clause = ""
end
end
end
::requires "extension/extensions.cls"
::requires "concurrency/coactivity.cls"
::requires "pipeline/pipe_extension.cls"
::requires "rgf_util2/rgf_util2_wrappers"

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks