Diff of /sandbox/jlf/samples/rgf_util2/rgf_util2_wrappers.rex [r7647] .. [r7648]  Maximize  Restore

  Switch to unified view

a/sandbox/jlf/samples/rgf_util2/rgf_util2_wrappers.rex b/sandbox/jlf/samples/rgf_util2/rgf_util2_wrappers.rex
1
/*
1
/*
2
rgf_util2 wrappers to make the services available as methods on predefined classes.
2
rgf_util2 wrappers to make the services available as methods on predefined classes.
3
Quickly implemented, but could be more efficient...
3
Quickly implemented, but could be more efficient...
4
obj~method2(args) --> routine(obj, reworked_args) --> obj~method(re_reworked_args) 
4
obj~method2(args) --> routine(obj, reworked_args) --> obj~method(re_reworked_args)
5
5
6
For a real library of methods, an rgf_util2_oo.rex should be written to use the variable 
6
For a real library of methods, an rgf_util2_oo.rex should be written to use the variable
7
"self" where appropriate, instead of passing the object as first parameter.
7
"self" where appropriate, instead of passing the object as first parameter.
8
obj~method2(args) --> obj~method(reworked_args)
8
obj~method2(args) --> obj~method(reworked_args)
9
*/
9
*/
10
10
11
::requires "rgf_util2/rgf_util2.rex"
11
::requires "rgf_util2/rgf_util2.rex"
...
...
16
-- The only way to keep them omitted is to pass the arguments array.
16
-- The only way to keep them omitted is to pass the arguments array.
17
-- The self object must be inserted in the list of arguments, most of the time in first position,
17
-- The self object must be inserted in the list of arguments, most of the time in first position,
18
-- but sometimes in second position (like changeStr2).
18
-- but sometimes in second position (like changeStr2).
19
19
20
::extension Object
20
::extension Object
21
-- Beware ! .nil is somewhat bizarre and can't be extended, i.e. .nil~pp2 will raise "does not understand"
21
::method pp2 ; return pp2~call(self, .context~args)
22
::method pp2 ; return pp2~call(self, .context~args)
22
::method ppIndex2 ; return ppIndex2~call(self, .context~args)
23
::method ppIndex2 ; return ppIndex2~call(self, .context~args)
24
-- Sometimes I want the maximum of details, whatever the object. Will be redefined for collections.
25
::method dump2 ; say pp2~call(self, .context~args) ; return self
26
27
28
::routine dump public
29
    -- .nil can't be extended, so must find a way to dump *ANY* object with all the details, including .nil
30
    -- Since a method can't do that, a routine will do !
31
    use strict arg object
32
    if object == .nil then say pp2(object)
33
    else if object~class == .class then say pp2(object)
34
    else object~dump2
35
    return object
23
36
24
37
25
::extension String
38
::extension String
26
::method abbrev2 ; return abbrev2~call(self, .context~args)
39
::method abbrev2 ; return abbrev2~call(self, .context~args)
27
::method changeStr2 ; return changeStr2~call(self, .context~args, 2)
40
::method changeStr2 ; return changeStr2~call(self, .context~args, 2)
...
...
47
::method escape2 ; return escape2~call(self, .context~args)
60
::method escape2 ; return escape2~call(self, .context~args)
48
::method enquote2 ; return enquote2~call(self, .context~args)
61
::method enquote2 ; return enquote2~call(self, .context~args)
49
62
50
63
51
::extension Collection
64
::extension Collection
52
::method dump2 ; dump2~call(self, .context~args)
65
::method dump2 ; dump2~call(self, .context~args) ; return self
53
::method makeRelation2 ; return makeRelation2~call(self, .context~args)
66
::method makeRelation2 ; return makeRelation2~call(self, .context~args)
54
67
55
68
56
::extension Array
69
::extension Array
57
::method sort2 ; return sort2~call(self, .context~args)
70
::method sort2 ; return sort2~call(self, .context~args)
58
::method stableSort2 ; return stableSort2~call(self, .context~args)
71
::method stableSort2 ; return stableSort2~call(self, .context~args)
59
72
60
73
61
::extension Supplier
74
::extension Supplier
62
::method dump2 ; dump2~call(self, .context~args)
75
::method dump2 ; dump2~call(self, .context~args) ; return self
63
76
64
77
65
::extension Method
78
::extension Method
66
::method ppMethod2 ; return ppMethod2~call(self, .context~args)
79
::method ppMethod2 ; return ppMethod2~call(self, .context~args)
67
80
...
...
89
   item2 = self[index2]
102
   item2 = self[index2]
90
   self[index1] = item2
103
   self[index1] = item2
91
   self[index2] = item1
104
   self[index2] = item1
92
   return self
105
   return self
93
106
94
    
107
95
::extension String
108
::extension String
96
::method call
109
::method call
97
    -- Here, the string (self) is the name of a routine
110
    -- Here, the string (self) is the name of a routine
98
    -- Call this routine by passing object as first parameter (default)
111
    -- Call this routine by passing object as first parameter (default)
99
    use strict arg object, argsArray, objectPos=1
112
    use strict arg object, argsArray, objectPos=1

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

Sign up for the SourceForge newsletter:





No, thanks