scicom 0.2.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +674 -0
  3. data/README.md +66 -0
  4. data/README.md~ +290 -0
  5. data/Rakefile +51 -0
  6. data/config.rb +163 -0
  7. data/doc/PypeR.pdf +0 -0
  8. data/doc/Stat 133 Class Notes (Phil Spector).pdf +29905 -45
  9. data/doc/The R interface.docx +0 -0
  10. data/lib/JRubyR/as_mdarray.rb +60 -0
  11. data/lib/JRubyR/attributes.rb +74 -0
  12. data/lib/JRubyR/dataframe.rb +35 -0
  13. data/lib/JRubyR/environment.rb +60 -0
  14. data/lib/JRubyR/function.rb +61 -0
  15. data/lib/JRubyR/index.rb +278 -0
  16. data/lib/JRubyR/list.rb +56 -0
  17. data/lib/JRubyR/list_orig.rb +111 -0
  18. data/lib/JRubyR/logical_value.rb +56 -0
  19. data/lib/JRubyR/rbsexp.rb +386 -0
  20. data/lib/JRubyR/renjin.rb +431 -0
  21. data/lib/JRubyR/ruby_classes.rb +58 -0
  22. data/lib/JRubyR/sequence.rb +56 -0
  23. data/lib/JRubyR/vector.rb +493 -0
  24. data/lib/env.rb +12 -0
  25. data/lib/rinruby.rb +795 -0
  26. data/lib/scicom.rb +29 -0
  27. data/target/helper.jar +0 -0
  28. data/test/baseball.csv +1 -0
  29. data/test/env.rb +7 -0
  30. data/test/test_R_interface.rb +165 -0
  31. data/test/test_array.rb +191 -0
  32. data/test/test_attributes.rb +261 -0
  33. data/test/test_basic.rb +156 -0
  34. data/test/test_column-major.rb +114 -0
  35. data/test/test_complete.rb +49 -0
  36. data/test/test_creation.rb +299 -0
  37. data/test/test_dataframe.rb +248 -0
  38. data/test/test_distribution.rb +320 -0
  39. data/test/test_double_assign.rb +240 -0
  40. data/test/test_double_receive.rb +106 -0
  41. data/test/test_environment.rb +57 -0
  42. data/test/test_factor.rb +285 -0
  43. data/test/test_functions.rb +67 -0
  44. data/test/test_linear_model.rb +64 -0
  45. data/test/test_list.rb +220 -0
  46. data/test/test_matrix.rb +205 -0
  47. data/test/test_mdarray.rb +258 -0
  48. data/test/test_operators.rb +227 -0
  49. data/test/test_sequence.rb +63 -0
  50. data/test/test_subsetting.rb +67 -0
  51. data/test/test_tmp.rb +67 -0
  52. data/test/test_vector.rb +227 -0
  53. data/vendor/Renjin.pdf +0 -0
  54. data/vendor/renjin-script-engine-0.7.0-RC7-SNAPSHOT-jar-with-dependencies.jar +0 -0
  55. data/version.rb +2 -0
  56. metadata +196 -0
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ class Renjin
25
+
26
+ class List < Renjin::RubySexp
27
+ include Renjin::Index
28
+
29
+ #----------------------------------------------------------------------------------------
30
+ #
31
+ #----------------------------------------------------------------------------------------
32
+
33
+ def initialize(sexp)
34
+ super(sexp)
35
+ @iterator = @sexp.iterator()
36
+ end
37
+
38
+ #----------------------------------------------------------------------------------------
39
+ #
40
+ #----------------------------------------------------------------------------------------
41
+
42
+ def names
43
+ R.names(self)
44
+ end
45
+
46
+ #----------------------------------------------------------------------------------------
47
+ #
48
+ #----------------------------------------------------------------------------------------
49
+
50
+ def unlist
51
+ R.unlist(self)
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,111 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ class List < Vector
25
+
26
+ #----------------------------------------------------------------------------------------
27
+ #
28
+ #----------------------------------------------------------------------------------------
29
+
30
+ def length
31
+ @sexp.length()
32
+ end
33
+
34
+ #----------------------------------------------------------------------------------------
35
+ # index can be a numeric index or a string index.
36
+ #----------------------------------------------------------------------------------------
37
+
38
+ def get(index)
39
+ RubySexp.build(@sexp.get(index))
40
+ end
41
+
42
+ #----------------------------------------------------------------------------------------
43
+ #
44
+ #----------------------------------------------------------------------------------------
45
+
46
+ def [](index)
47
+ get(index)
48
+ end
49
+
50
+ #----------------------------------------------------------------------------------------
51
+ #
52
+ #----------------------------------------------------------------------------------------
53
+
54
+ def index_of_name(name)
55
+ @sexp.indexOfName(name)
56
+ end
57
+
58
+ #----------------------------------------------------------------------------------------
59
+ # index can be a numeric index or a string index.
60
+ #----------------------------------------------------------------------------------------
61
+
62
+ def get_element_as_double(index)
63
+ @sexp.getElementAsDouble(index)
64
+ end
65
+
66
+ #----------------------------------------------------------------------------------------
67
+ # index can be a numeric index or a string index.
68
+ #----------------------------------------------------------------------------------------
69
+
70
+ def get_element_as_int(index)
71
+ @sexp.getElementAsInt(index)
72
+ end
73
+
74
+ #----------------------------------------------------------------------------------------
75
+ #
76
+ #----------------------------------------------------------------------------------------
77
+
78
+ def get_element_as_list(name)
79
+ RubySexp.build(@sexp.getElementAsList(name))
80
+ end
81
+
82
+ #----------------------------------------------------------------------------------------
83
+ #
84
+ #----------------------------------------------------------------------------------------
85
+
86
+ def get_element_as_vector(name)
87
+ RubySexp.build(@sexp.getElementAsVector(name))
88
+ end
89
+
90
+ #----------------------------------------------------------------------------------------
91
+ # Treats ruby style methods in lists as named items on the list
92
+ #----------------------------------------------------------------------------------------
93
+
94
+ def method_missing(symbol, *args)
95
+
96
+ name = symbol.id2name
97
+ name.gsub!(/__/,".")
98
+ # super if args.length != 0
99
+ if (args.length == 0)
100
+ # treat name as a named item of the list
101
+ ret = R.eval("#{r}[\"#{name}\"]")[0]
102
+ else
103
+ raise "Illegal argument for named list item #{name}"
104
+ end
105
+
106
+ ret
107
+
108
+ end
109
+
110
+ end
111
+
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ #==========================================================================================
25
+ #
26
+ #==========================================================================================
27
+
28
+ require 'java'
29
+
30
+ class Renjin
31
+
32
+ class Logical < Renjin::Vector
33
+
34
+ #----------------------------------------------------------------------------------------
35
+ #
36
+ #----------------------------------------------------------------------------------------
37
+
38
+ def each(&block)
39
+ while (@iterator.hasNext())
40
+ block.call((@iterator.next().getInternalValue() == 1)? true : false)
41
+ end
42
+ end
43
+
44
+ #----------------------------------------------------------------------------------------
45
+ # Renjin bug? toString of a LogicalVector in Renjin is returing a LogicalVector and not
46
+ # a string. Need to take care of this here.
47
+ # to_a converts an Enumerable to an array
48
+ #----------------------------------------------------------------------------------------
49
+
50
+ def to_string
51
+ to_a.join(",")
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,386 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # @author Rodrigo Botafogo
5
+ #
6
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
7
+ # and distribute this software and its documentation, without fee and without a signed
8
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
9
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
10
+ # distributions.
11
+ #
12
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
13
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
14
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
15
+ # POSSIBILITY OF SUCH DAMAGE.
16
+ #
17
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
19
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
20
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
21
+ # OR MODIFICATIONS.
22
+ ##########################################################################################
23
+
24
+ require_relative "attributes"
25
+
26
+ #==========================================================================================
27
+ #
28
+ #==========================================================================================
29
+
30
+ class Renjin
31
+
32
+ module Index
33
+
34
+ #----------------------------------------------------------------------------------------
35
+ #
36
+ #----------------------------------------------------------------------------------------
37
+
38
+ def [](*index)
39
+ index = parse(index)
40
+ R.eval("#{r}[#{index}]")
41
+ end
42
+
43
+ #----------------------------------------------------------------------------------------
44
+ #
45
+ #----------------------------------------------------------------------------------------
46
+
47
+ def []=(*index, value)
48
+ index = parse(index)
49
+ value = R.parse(value)
50
+ R.eval("#{r}[#{index}] = #{value}")
51
+ end
52
+
53
+ #----------------------------------------------------------------------------------------
54
+ #
55
+ #----------------------------------------------------------------------------------------
56
+
57
+ def parse(index)
58
+
59
+ params = Array.new
60
+
61
+ index.each do |i|
62
+ if (i.is_a? Array)
63
+ params << i
64
+ else
65
+ params << R.parse(i)
66
+ end
67
+ end
68
+
69
+ ps = String.new
70
+ params.each_with_index do |p, i|
71
+ ps << "," if i > 0
72
+ ps << ((p == "NULL")? "" : p.to_s)
73
+ end
74
+
75
+ ps
76
+
77
+ end
78
+
79
+ #----------------------------------------------------------------------------------------
80
+ #
81
+ #----------------------------------------------------------------------------------------
82
+
83
+ def method_missing(symbol, *args)
84
+
85
+ name = symbol.id2name
86
+ name.gsub!(/__/,".")
87
+
88
+ # super if args.length != 0
89
+ if name =~ /(.*)=$/
90
+ super if args.length != 1
91
+ # p "#{r}$#{$1} = #{args[0].r}"
92
+ # ret = R.eval("#{r}[\"#{name}\"] = #{args[0].r}")
93
+ ret = R.eval("#{r}$#{$1} = #{args[0].r}")
94
+ elsif (name == "_")
95
+ method = "%#{args.shift.to_s}%"
96
+ arg2 = R.parse(*args)
97
+ ret = R.eval("#{r} #{method} #{arg2}")
98
+ elsif (args.length == 0)
99
+ # treat name as a named item of the list
100
+ if (R.eval("\"#{name}\" %in% names(#{r})").gt)
101
+ ret = R.eval("#{r}[[\"#{name}\"]]")
102
+ else
103
+ ret = R.eval("#{name}(#{r})") if ret == nil
104
+ end
105
+ elsif (args.length > 0)
106
+ # p "#{name}(#{r}, #{R.parse(*args)})"
107
+ ret = R.eval("#{name}(#{r}, #{R.parse(*args)})")
108
+ else
109
+ raise "Illegal argument for named list item #{name}"
110
+ end
111
+
112
+ ret
113
+
114
+ end
115
+
116
+ #----------------------------------------------------------------------------------------
117
+ #
118
+ #----------------------------------------------------------------------------------------
119
+
120
+ def length
121
+ R.length(R.eval("#{r}")).gz
122
+ end
123
+
124
+ #----------------------------------------------------------------------------------------
125
+ #
126
+ #----------------------------------------------------------------------------------------
127
+
128
+ def each(&block)
129
+ while (@iterator.hasNext())
130
+ block.call(@iterator.next())
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ #==========================================================================================
137
+ #
138
+ #==========================================================================================
139
+
140
+ module RBSexp
141
+ include_package "org.renjin"
142
+ include_package "java.lang"
143
+
144
+ attr_reader :sexp
145
+ attr_reader :rvar
146
+ attr_reader :attr
147
+ attr_accessor :scope
148
+
149
+ #----------------------------------------------------------------------------------------
150
+ #
151
+ #----------------------------------------------------------------------------------------
152
+
153
+ def destroy
154
+
155
+ if (@rvar != nil)
156
+ @sexp = R.direct_eval("#{@rvar}")
157
+ # change value in the scope
158
+ if (@scope)
159
+ R.direct_eval("#{scope[0]}(#{scope[1].r}, \"#{scope[2]}\") = #{@rvar}")
160
+ # @scope = nil
161
+ end
162
+ R.direct_eval("rm('#{@rvar}')")
163
+ @rvar = nil
164
+
165
+ end
166
+
167
+ end
168
+
169
+ #----------------------------------------------------------------------------------------
170
+ #
171
+ #----------------------------------------------------------------------------------------
172
+
173
+ def r
174
+
175
+ if (@rvar == nil)
176
+ @rvar = "sc_#{SecureRandom.hex(8)}"
177
+ (@sexp == nil)? R.assign(@rvar, self) : R.assign(@rvar, @sexp)
178
+ # Whenever a variable is injected in Renjin, it is also added to the Renjin stack.
179
+ # After eval, every injected variable is removed from Renjin making sure that we
180
+ # do not have memory leak.
181
+ Renjin.stack << self
182
+ end
183
+
184
+ @rvar
185
+
186
+ end
187
+
188
+ #----------------------------------------------------------------------------------------
189
+ # * @return true if this RubySexp already points to a sexp in R environment
190
+ #----------------------------------------------------------------------------------------
191
+
192
+ def sexp?
193
+ sexp != nil
194
+ end
195
+
196
+ #----------------------------------------------------------------------------------------
197
+ #
198
+ #----------------------------------------------------------------------------------------
199
+
200
+ def unbind
201
+ @scope = nil
202
+ end
203
+
204
+ #----------------------------------------------------------------------------------------
205
+ #
206
+ #----------------------------------------------------------------------------------------
207
+
208
+ def typeof
209
+ R.typeof(R.eval("#{r}"))
210
+ end
211
+
212
+ #----------------------------------------------------------------------------------------
213
+ #
214
+ #----------------------------------------------------------------------------------------
215
+
216
+ def rclass
217
+ R.rclass(R.eval("#{r}"))
218
+ end
219
+
220
+ #----------------------------------------------------------------------------------------
221
+ #
222
+ #----------------------------------------------------------------------------------------
223
+
224
+ def print
225
+ R.eval("print(#{r})")
226
+ end
227
+
228
+ #----------------------------------------------------------------------------------------
229
+ #
230
+ #----------------------------------------------------------------------------------------
231
+
232
+ def pp
233
+ print
234
+ end
235
+
236
+ #----------------------------------------------------------------------------------------
237
+ #
238
+ #----------------------------------------------------------------------------------------
239
+
240
+ def nrow
241
+ R.nrow(self)
242
+ end
243
+
244
+ #----------------------------------------------------------------------------------------
245
+ #
246
+ #----------------------------------------------------------------------------------------
247
+
248
+ def ncol
249
+ R.ncol(self)
250
+ end
251
+
252
+ end
253
+
254
+ end
255
+
256
+ #==========================================================================================
257
+ # Make a Ruby Array into a RBSexp
258
+ #==========================================================================================
259
+
260
+ class Array
261
+ include Renjin::RBSexp
262
+ end
263
+
264
+ #==========================================================================================
265
+ #
266
+ #==========================================================================================
267
+
268
+ class Renjin
269
+
270
+ class RubySexp
271
+ include Renjin::RBSexp
272
+
273
+ #----------------------------------------------------------------------------------------
274
+ #
275
+ #----------------------------------------------------------------------------------------
276
+
277
+ def initialize(sexp)
278
+
279
+ @sexp = sexp
280
+ @rvar = nil
281
+ @attr = Attributes.new(self)
282
+
283
+ end
284
+
285
+ #----------------------------------------------------------------------------------------
286
+ #
287
+ #----------------------------------------------------------------------------------------
288
+
289
+ def to_string
290
+ R.eval("toString(#{r})")
291
+ end
292
+
293
+ #----------------------------------------------------------------------------------------
294
+ #
295
+ #----------------------------------------------------------------------------------------
296
+
297
+ def fassign(function, value)
298
+ R.fassign(self, function, value)
299
+ end
300
+
301
+ #----------------------------------------------------------------------------------------
302
+ #
303
+ #----------------------------------------------------------------------------------------
304
+
305
+ def self.build(sexp)
306
+
307
+ if (sexp.instance_of? Java::OrgRenjinPrimitivesSequence::IntSequence)
308
+ res = Renjin::Sequence.new(sexp)
309
+ elsif (sexp.instance_of? Java::OrgRenjinSexp::Null)
310
+ res = nil
311
+ elsif (sexp.instance_of? Java::OrgRenjinSexp::ListVector)
312
+ res = Renjin::List.new(sexp)
313
+ elsif (sexp.instance_of? Java::OrgRenjinSexp::LogicalArrayVector)
314
+ res = Renjin::Logical.new(sexp)
315
+ elsif (sexp.instance_of? Java::OrgRenjinSexp::Environment)
316
+ res = Renjin::Environment.new(sexp)
317
+ elsif (sexp.is_a? Java::OrgRenjinSexp::ComplexVector)
318
+ res = Renjin::ComplexVector.new(sexp)
319
+ elsif (sexp.is_a? Java::OrgRenjinSexp::Vector)
320
+ res = Renjin::Vector.new(sexp)
321
+ elsif (sexp.is_a? Java::OrgRenjinSexp::Closure)
322
+ res = Renjin::Closure.new(sexp)
323
+ # elsif (sexp.is_a? Java::OrgRenjinPrimitives::R$primitive$sum)
324
+ # res = Renjin::Primitive.new(sexp)
325
+ else
326
+ p "sexp type needs to be specialized"
327
+ p sexp
328
+ res = Renjin::RubySexp.new(sexp)
329
+ end
330
+
331
+ return res
332
+
333
+ end
334
+
335
+ end
336
+
337
+ end
338
+
339
+ require_relative 'ruby_classes'
340
+ require_relative 'vector'
341
+ require_relative 'sequence'
342
+ require_relative 'list'
343
+ require_relative 'function'
344
+ require_relative 'logical_value'
345
+ require_relative 'environment'
346
+
347
+
348
+ =begin
349
+ #----------------------------------------------------------------------------------------
350
+ #
351
+ #----------------------------------------------------------------------------------------
352
+
353
+ def set_sexp(sexp)
354
+ @sexp = sexp
355
+ end
356
+
357
+ #----------------------------------------------------------------------------------------
358
+ #
359
+ #----------------------------------------------------------------------------------------
360
+
361
+ def method_missing(symbol, *args)
362
+
363
+ name = symbol.id2name
364
+ name.gsub!(/__/,".")
365
+
366
+ # super if args.length != 0
367
+ if name =~ /(.*)=$/
368
+ super if args.length != 1
369
+ args = R.parse(*args)
370
+ ret = R.eval("#{r}[[\"#{name}\"]] = #{args}")
371
+ elsif (args.length == 0)
372
+ # treat name as a named item of the list
373
+ ret = R.eval("#{r}[[\"#{name}\"]]")
374
+ elsif (name == "_")
375
+ method = "%#{args.shift.to_s}%"
376
+ arg2 = R.parse(*args)
377
+ ret = R.eval("#{r} #{method} #{arg2}")
378
+ else
379
+ raise "Illegal argument for named list item #{name}"
380
+ end
381
+
382
+ ret
383
+
384
+ end
385
+
386
+ =end