fancy 0.3.0 → 0.3.1

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 (113) hide show
  1. data/{README → README.md} +33 -50
  2. data/Rakefile +6 -1
  3. data/bin/fyi +13 -10
  4. data/boot/fancy_ext.rb +1 -0
  5. data/boot/fancy_ext/block_env.rb +6 -2
  6. data/boot/fancy_ext/console.rb +4 -0
  7. data/boot/fancy_ext/object.rb +6 -0
  8. data/boot/rbx-compiler/compiler/ast/identifier.rb +5 -1
  9. data/boot/rbx-compiler/compiler/ast/match.rb +4 -5
  10. data/boot/rbx-compiler/compiler/ast/super.rb +1 -0
  11. data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
  12. data/boot/rbx-compiler/parser/lexer.c +2316 -0
  13. data/boot/rbx-compiler/parser/lexer.h +315 -0
  14. data/boot/rbx-compiler/parser/parser.c +3105 -0
  15. data/boot/rbx-compiler/parser/parser.h +114 -0
  16. data/boot/rbx-compiler/parser/parser.rb +2 -2
  17. data/boot/rbx-compiler/parser/parser.y +3 -3
  18. data/doc/api/fancy.jsonp +1 -1
  19. data/doc/features.md +14 -3
  20. data/examples/async_send.fy +11 -0
  21. data/examples/fibonacci.fy +1 -1
  22. data/examples/future.fy +30 -0
  23. data/examples/futures.fy +14 -0
  24. data/examples/game_of_life.fy +1 -1
  25. data/examples/matchers.fy +1 -1
  26. data/examples/pattern_matching.fy +3 -3
  27. data/examples/stupid_quicksort.fy +1 -1
  28. data/examples/threads.fy +1 -1
  29. data/extconf.rb +7 -0
  30. data/lib/array.fy +25 -5
  31. data/lib/block.fy +20 -18
  32. data/lib/boot.fy +7 -2
  33. data/lib/class.fy +33 -2
  34. data/lib/compiler/ast.fy +2 -0
  35. data/lib/compiler/ast/assign.fy +5 -5
  36. data/lib/compiler/ast/async_send.fy +25 -0
  37. data/lib/compiler/ast/block.fy +3 -3
  38. data/lib/compiler/ast/future_send.fy +20 -0
  39. data/lib/compiler/ast/identifier.fy +13 -7
  40. data/lib/compiler/ast/match.fy +32 -22
  41. data/lib/compiler/ast/message_send.fy +4 -4
  42. data/lib/compiler/ast/method_def.fy +1 -1
  43. data/lib/compiler/ast/script.fy +2 -2
  44. data/lib/compiler/ast/super.fy +1 -0
  45. data/lib/compiler/compiler.fy +2 -0
  46. data/lib/documentation.fy +4 -4
  47. data/lib/enumerable.fy +14 -7
  48. data/lib/fancy_spec.fy +2 -2
  49. data/lib/fdoc.fy +7 -7
  50. data/lib/fiber.fy +11 -0
  51. data/lib/fiber_pool.fy +78 -0
  52. data/lib/file.fy +1 -1
  53. data/lib/future.fy +32 -0
  54. data/lib/hash.fy +5 -5
  55. data/lib/lazy_array.fy +23 -0
  56. data/lib/main.fy +35 -25
  57. data/lib/method.fy +1 -1
  58. data/lib/nil_class.fy +4 -0
  59. data/lib/object.fy +59 -7
  60. data/lib/package.fy +11 -2
  61. data/lib/package/installer.fy +50 -20
  62. data/lib/package/list.fy +34 -0
  63. data/lib/package/specification.fy +19 -1
  64. data/lib/parser/ext/Makefile +162 -0
  65. data/lib/parser/ext/lexer.c +2360 -0
  66. data/lib/parser/ext/lexer.h +315 -0
  67. data/lib/parser/ext/lexer.lex +4 -0
  68. data/lib/parser/ext/parser.c +3382 -0
  69. data/lib/parser/ext/parser.h +118 -0
  70. data/lib/parser/ext/parser.y +43 -3
  71. data/lib/parser/methods.fy +34 -7
  72. data/lib/parser/parse_error.fy +10 -0
  73. data/lib/proxy.fy +16 -0
  74. data/lib/rbx.fy +3 -0
  75. data/lib/rbx/array.fy +78 -40
  76. data/lib/rbx/block.fy +35 -1
  77. data/lib/rbx/class.fy +5 -3
  78. data/lib/rbx/code_loader.fy +6 -6
  79. data/lib/rbx/console.fy +1 -1
  80. data/lib/rbx/date.fy +12 -0
  81. data/lib/rbx/documentation.fy +5 -5
  82. data/lib/rbx/exception.fy +1 -1
  83. data/lib/rbx/fiber.fy +4 -8
  84. data/lib/rbx/file.fy +4 -3
  85. data/lib/rbx/fixnum.fy +1 -0
  86. data/lib/rbx/float.fy +1 -0
  87. data/lib/rbx/hash.fy +3 -2
  88. data/lib/rbx/io.fy +5 -5
  89. data/lib/rbx/match_data.fy +10 -0
  90. data/lib/rbx/method.fy +4 -4
  91. data/lib/rbx/no_method_error.fy +1 -1
  92. data/lib/rbx/object.fy +8 -15
  93. data/lib/rbx/regexp.fy +4 -0
  94. data/lib/rbx/string.fy +39 -1
  95. data/lib/rbx/symbol.fy +1 -1
  96. data/lib/rbx/system.fy +0 -6
  97. data/lib/rbx/thread.fy +5 -0
  98. data/lib/rbx/time.fy +14 -0
  99. data/lib/rbx/tuple.fy +1 -0
  100. data/lib/set.fy +1 -1
  101. data/lib/stack.fy +1 -1
  102. data/lib/string.fy +2 -2
  103. data/lib/thread_pool.fy +101 -0
  104. data/lib/tuple.fy +37 -6
  105. data/ruby_lib/fancy.rb +46 -0
  106. data/tests/block.fy +39 -0
  107. data/tests/class.fy +40 -1
  108. data/tests/file.fy +2 -2
  109. data/tests/hash.fy +7 -7
  110. data/tests/nil_class.fy +2 -2
  111. data/tests/object.fy +10 -2
  112. data/tests/pattern_matching.fy +18 -7
  113. metadata +34 -7
@@ -0,0 +1,118 @@
1
+ /* A Bison parser, made by GNU Bison 2.4.3. */
2
+
3
+ /* Skeleton interface for Bison's Yacc-like parsers in C
4
+
5
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
6
+ 2009, 2010 Free Software Foundation, Inc.
7
+
8
+ This program is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation, either version 3 of the License, or
11
+ (at your option) any later version.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
+
21
+ /* As a special exception, you may create a larger work that contains
22
+ part or all of the Bison parser skeleton and distribute that work
23
+ under terms of your choice, so long as that work isn't itself a
24
+ parser generator using the skeleton or a modified version thereof
25
+ as a parser skeleton. Alternatively, if you modify or redistribute
26
+ the parser skeleton itself, you may (at your option) remove this
27
+ special exception, which will cause the skeleton and the resulting
28
+ Bison output files to be licensed under the GNU General Public
29
+ License without this special exception.
30
+
31
+ This special exception was added by the Free Software Foundation in
32
+ version 2.2 of Bison. */
33
+
34
+
35
+ /* Tokens. */
36
+ #ifndef YYTOKENTYPE
37
+ # define YYTOKENTYPE
38
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
39
+ know about them. */
40
+ enum yytokentype {
41
+ LPAREN = 258,
42
+ RPAREN = 259,
43
+ FUTURE_SEND = 260,
44
+ ASYNC_SEND = 261,
45
+ AT_LCURLY = 262,
46
+ LCURLY = 263,
47
+ RCURLY = 264,
48
+ LBRACKET = 265,
49
+ RBRACKET = 266,
50
+ LHASH = 267,
51
+ RHASH = 268,
52
+ STAB = 269,
53
+ ARROW = 270,
54
+ THIN_ARROW = 271,
55
+ COMMA = 272,
56
+ SEMI = 273,
57
+ NL = 274,
58
+ COLON = 275,
59
+ RETURN_LOCAL = 276,
60
+ RETURN = 277,
61
+ REQUIRE = 278,
62
+ TRY = 279,
63
+ CATCH = 280,
64
+ FINALLY = 281,
65
+ RETRY = 282,
66
+ SUPER = 283,
67
+ PRIVATE = 284,
68
+ PROTECTED = 285,
69
+ CLASS = 286,
70
+ DEF = 287,
71
+ DOT = 288,
72
+ DOLLAR = 289,
73
+ EQUALS = 290,
74
+ MATCH = 291,
75
+ CASE = 292,
76
+ IDENTIFIER = 293,
77
+ SELECTOR = 294,
78
+ RUBY_SEND_OPEN = 295,
79
+ RUBY_OPER_OPEN = 296,
80
+ CONSTANT = 297,
81
+ INTEGER_LITERAL = 298,
82
+ HEX_LITERAL = 299,
83
+ OCT_LITERAL = 300,
84
+ BIN_LITERAL = 301,
85
+ DOUBLE_LITERAL = 302,
86
+ STRING_LITERAL = 303,
87
+ MULTI_STRING_LITERAL = 304,
88
+ SYMBOL_LITERAL = 305,
89
+ REGEX_LITERAL = 306,
90
+ OPERATOR = 307
91
+ };
92
+ #endif
93
+
94
+
95
+
96
+ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
97
+ typedef union YYSTYPE
98
+ {
99
+
100
+ /* Line 1685 of yacc.c */
101
+ #line 18 "/Users/backtype/projects/fancy/lib/parser/ext/parser.y"
102
+
103
+ VALUE object;
104
+ ID symbol;
105
+
106
+
107
+
108
+ /* Line 1685 of yacc.c */
109
+ #line 110 "/Users/backtype/projects/fancy/lib/parser/ext/parser.h"
110
+ } YYSTYPE;
111
+ # define YYSTYPE_IS_TRIVIAL 1
112
+ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
113
+ # define YYSTYPE_IS_DECLARED 1
114
+ #endif
115
+
116
+ extern YYSTYPE yylval;
117
+
118
+
@@ -24,6 +24,8 @@ extern char *yytext;
24
24
 
25
25
  %token LPAREN
26
26
  %token RPAREN
27
+ %token FUTURE_SEND
28
+ %token ASYNC_SEND
27
29
  %token AT_LCURLY
28
30
  %token LCURLY
29
31
  %token RCURLY
@@ -419,6 +421,18 @@ unary_send: exp identifier {
419
421
  | unary_send identifier {
420
422
  $$ = rb_funcall(self, rb_intern("ast:send:to:"), 3, INT2NUM(yylineno), $2, $1);
421
423
  }
424
+ | exp FUTURE_SEND identifier {
425
+ $$ = rb_funcall(self, rb_intern("ast:future_send:to:"), 3, INT2NUM(yylineno), $3, $1);
426
+ }
427
+ | unary_send FUTURE_SEND identifier {
428
+ $$ = rb_funcall(self, rb_intern("ast:future_send:to:"), 3, INT2NUM(yylineno), $3, $1);
429
+ }
430
+ | exp ASYNC_SEND identifier {
431
+ $$ = rb_funcall(self, rb_intern("ast:async_send:to:"), 3, INT2NUM(yylineno), $3, $1);
432
+ }
433
+ | unary_send ASYNC_SEND identifier {
434
+ $$ = rb_funcall(self, rb_intern("ast:async_send:to:"), 3, INT2NUM(yylineno), $3, $1);
435
+ }
422
436
  ;
423
437
 
424
438
  operator_send: exp operator arg_exp {
@@ -434,6 +448,26 @@ operator_send: exp operator arg_exp {
434
448
  | operator arg_exp {
435
449
  $$ = rb_funcall(self, rb_intern("ast:oper:arg:"), 3, INT2NUM(yylineno), $1, $2);
436
450
  }
451
+ | exp FUTURE_SEND operator arg_exp {
452
+ $$ = rb_funcall(self, rb_intern("ast:future_oper:arg:to:"), 4, INT2NUM(yylineno), $3, $4, $1);
453
+ }
454
+ | exp FUTURE_SEND operator DOT space arg_exp {
455
+ $$ = rb_funcall(self, rb_intern("ast:future_oper:arg:to:"), 4, INT2NUM(yylineno), $3, $6, $1);
456
+ }
457
+ | exp FUTURE_SEND LBRACKET exp RBRACKET {
458
+ $$ = rb_funcall(self, rb_intern("ast:future_oper:arg:to:"), 4,
459
+ INT2NUM(yylineno), fy_terminal_node_from(self, "ast:identifier:", "[]"), $4, $1);
460
+ }
461
+ | exp ASYNC_SEND operator arg_exp {
462
+ $$ = rb_funcall(self, rb_intern("ast:async_oper:arg:to:"), 4, INT2NUM(yylineno), $3, $4, $1);
463
+ }
464
+ | exp ASYNC_SEND operator DOT space arg_exp {
465
+ $$ = rb_funcall(self, rb_intern("ast:async_oper:arg:to:"), 4, INT2NUM(yylineno), $3, $6, $1);
466
+ }
467
+ | exp ASYNC_SEND LBRACKET exp RBRACKET {
468
+ $$ = rb_funcall(self, rb_intern("ast:async_oper:arg:to:"), 4,
469
+ INT2NUM(yylineno), fy_terminal_node_from(self, "ast:identifier:", "[]"), $4, $1);
470
+ }
437
471
  ;
438
472
 
439
473
  message_send: unary_send
@@ -444,6 +478,12 @@ message_send: unary_send
444
478
  | send_args {
445
479
  $$ = rb_funcall(self, rb_intern("ast:send:"), 2, INT2NUM(yylineno), $1);
446
480
  }
481
+ | exp FUTURE_SEND send_args {
482
+ $$ = rb_funcall(self, rb_intern("ast:future_send:to:"), 3, INT2NUM(yylineno), $3, $1);
483
+ }
484
+ | exp ASYNC_SEND send_args {
485
+ $$ = rb_funcall(self, rb_intern("ast:async_send:to:"), 3, INT2NUM(yylineno), $3, $1);
486
+ }
447
487
  ;
448
488
 
449
489
  send_args: selector arg_exp {
@@ -576,7 +616,7 @@ string_literal: STRING_LITERAL {
576
616
  $$ = fy_terminal_node(self, "ast:string:");
577
617
  }
578
618
  | MULTI_STRING_LITERAL {
579
- $$ = fy_terminal_node(self, "ast:string:");
619
+ $$ = fy_terminal_node(self, "ast:multi_line_string:");
580
620
  }
581
621
  ;
582
622
  symbol_literal: SYMBOL_LITERAL {
@@ -702,8 +742,8 @@ key_value_list: exp space ARROW space exp {
702
742
  }
703
743
  ;
704
744
 
705
- match_expr: MATCH exp THIN_ARROW LCURLY space match_body space RCURLY {
706
- $$ = rb_funcall(self, rb_intern("ast:match_expr:body:"), 3, INT2NUM(yylineno), $2, $6);
745
+ match_expr: MATCH exp LCURLY space match_body space RCURLY {
746
+ $$ = rb_funcall(self, rb_intern("ast:match_expr:body:"), 3, INT2NUM(yylineno), $2, $5);
707
747
  }
708
748
  ;
709
749
 
@@ -1,5 +1,9 @@
1
+ require: "parse_error"
2
+
1
3
  class Fancy {
2
4
  class Parser {
5
+ SelectorVarDefault = Struct.new('selector, 'variable, 'default)
6
+ SelectorValue = Struct new('selector, 'value)
3
7
 
4
8
  def self parse_file: filename line: line (1) {
5
9
  new: filename line: line . parse_file . script
@@ -60,7 +64,7 @@ class Fancy {
60
64
 
61
65
  def ast: line string: text {
62
66
  str = text from: 1 to: -2
63
- match str -> {
67
+ match str {
64
68
  # OK, I know this is ugly. But it works for now, so let's just go with it.
65
69
  # TODO: Clean this up or make it simpler...
66
70
 
@@ -89,6 +93,10 @@ class Fancy {
89
93
  }
90
94
  }
91
95
 
96
+ def ast: line multi_line_string: string {
97
+ ast: line string: (string from: 2 to: -3)
98
+ }
99
+
92
100
  def ast: line array: expr_ary {
93
101
  AST ArrayLiteral new: line array: expr_ary
94
102
  }
@@ -137,11 +145,11 @@ class Fancy {
137
145
  }
138
146
 
139
147
  def ast: line param: selector var: variable default: default (nil) {
140
- Struct.new('selector, 'variable, 'default) new(selector, variable, default)
148
+ SelectorVarDefault new(selector, variable, default)
141
149
  }
142
150
 
143
151
  def ast: line send: selector arg: value ary: ary ([]) {
144
- ary << $ Struct new('selector, 'value) new(selector, value)
152
+ ary << $ SelectorValue new(selector, value)
145
153
  }
146
154
 
147
155
  def ast: line oper: oper arg: arg to: receiver (AST Self new: line) {
@@ -149,6 +157,16 @@ class Fancy {
149
157
  ast: line send: message to: receiver
150
158
  }
151
159
 
160
+ def ast: line future_oper: oper arg: arg to: receiver {
161
+ oper_send = ast: line oper: oper arg: arg to: receiver
162
+ AST FutureSend new: line message_send: oper_send
163
+ }
164
+
165
+ def ast: line async_oper: oper arg: arg to: receiver {
166
+ oper_send = ast: line oper: oper arg: arg to: receiver
167
+ AST AsyncSend new: line message_send: oper_send
168
+ }
169
+
152
170
  def ast: line send: message to: receiver (AST Self new: line) ruby: ruby (nil) {
153
171
  args = ruby if_do: {
154
172
  unless: receiver do: {
@@ -171,6 +189,16 @@ class Fancy {
171
189
  AST MessageSend new: line message: name to: receiver args: args
172
190
  }
173
191
 
192
+ def ast: line future_send: message to: receiver ruby: ruby (nil) {
193
+ message_send = ast: line send: message to: receiver ruby: ruby
194
+ AST FutureSend new: line message_send: message_send
195
+ }
196
+
197
+ def ast: line async_send: message to: receiver ruby: ruby (nil) {
198
+ message_send = ast: line send: message to: receiver ruby: ruby
199
+ AST AsyncSend new: line message_send: message_send
200
+ }
201
+
174
202
  def method_name: margs {
175
203
  margs map: |a| { a selector() string } . join("")
176
204
  }
@@ -192,7 +220,7 @@ class Fancy {
192
220
 
193
221
  doc = AST StringLiteral new: line value: ("Forward to message " ++ target)
194
222
  body = AST ExpressionList new: line list: [doc, forward]
195
- block call: [[required, body]]
223
+ block call: [required, body]
196
224
  }
197
225
  }
198
226
  }
@@ -285,13 +313,12 @@ class Fancy {
285
313
  }
286
314
 
287
315
  def ast: line parse_error: text {
288
- ("Parse error near `" ++ text ++ "' at line " ++ line ++ " at " ++ @filename) . raise!
316
+ ParseError new: line message: text filename: @filename . raise!
289
317
  }
290
318
 
291
319
  def ast: line file_error: text {
292
- ("File error `" ++ text ++ "' while trying to parse " ++ @filename) . raise!
320
+ ("File error '" ++ text ++ "' while trying to parse " ++ @filename) . raise!
293
321
  }
294
-
295
322
  }
296
323
  }
297
324
 
@@ -0,0 +1,10 @@
1
+ class Fancy {
2
+ class Parser {
3
+ class ParseError : StdError {
4
+ read_slots: ['line, 'filename]
5
+ def initialize: @line message: @message filename: @filename {
6
+ initialize: $ "Parse error near '" ++ @message ++ "' at line " ++ @line ++ " in " ++ @filename
7
+ }
8
+ }
9
+ }
10
+ }
data/lib/proxy.fy ADDED
@@ -0,0 +1,16 @@
1
+ class ProxyReceiver : BasicObject {
2
+ """
3
+ A ProxyReceiver is an object which proxies all message sends to it to 2 other objects.
4
+ It will send each message first to its @proxy instance variable and then to the @obj instance variable.
5
+ """
6
+
7
+ def initialize: @proxy for: @obj {
8
+ }
9
+
10
+ def unknown_message: msg with_params: params {
11
+ @proxy send: msg params: params
12
+ @obj send: msg params: params
13
+ }
14
+ }
15
+
16
+ Proxy = ProxyReceiver
data/lib/rbx.fy CHANGED
@@ -35,3 +35,6 @@ require: "rbx/name_error"
35
35
  require: "rbx/no_method_error"
36
36
  require: "rbx/match_data"
37
37
  require: "rbx/thread"
38
+ require: "rbx/fiber"
39
+ require: "rbx/date"
40
+ require: "rbx/time"
data/lib/rbx/array.fy CHANGED
@@ -8,6 +8,8 @@ class Array {
8
8
  ruby_alias: 'sort
9
9
  ruby_alias: 'pop
10
10
  ruby_alias: 'last
11
+ ruby_alias: 'shuffle
12
+ ruby_alias: 'inspect
11
13
 
12
14
  def Array new: size with: default {
13
15
  "Creates a new Array with a given size and default-value."
@@ -27,12 +29,13 @@ class Array {
27
29
  arr each: |x| {
28
30
  self << x
29
31
  }
32
+ self
30
33
  }
31
34
 
32
35
  def includes?: obj {
33
36
  "Indicates, if an Array includes a given value."
34
37
 
35
- self include?(obj)
38
+ include?(obj)
36
39
  }
37
40
 
38
41
  def clone {
@@ -45,7 +48,12 @@ class Array {
45
48
  }
46
49
 
47
50
  def each: block {
48
- "Calls a given Block with each element in the Array."
51
+ """
52
+ @block @Block@ to be called for each element in @self.
53
+ @return Return value of calling @block on the last item in @self.
54
+
55
+ Calls a given @Block@ with each element in the @Array@.
56
+ """
49
57
 
50
58
  val = nil
51
59
  each() |x| { val = block call: [x] }
@@ -53,12 +61,14 @@ class Array {
53
61
  }
54
62
 
55
63
  def remove_at: index {
56
- """Removes an element at a given index.
57
- If given an Array of indices, removes all the elements with these indices.
58
- Returns the deleted object if an index was given, the last deleted object for an Array given."""
64
+ """
65
+ Removes an element at a given index.
66
+ If given an Array of indices, removes all the elements with these indices.
67
+ Returns the deleted object if an index was given, the last deleted object for an Array given.
68
+ """
59
69
 
60
70
  if: (index is_a?: Fixnum) then: {
61
- deleted = self at: index
71
+ deleted = at: index
62
72
  delete_at(index)
63
73
  return deleted
64
74
  } else: {
@@ -66,7 +76,7 @@ class Array {
66
76
  count = 0
67
77
  deleted_values = []
68
78
  index each: |idx| {
69
- deleted_values << (self at: (idx - count))
79
+ deleted_values << (at: (idx - count))
70
80
  delete_at(idx - count)
71
81
  count = count + 1
72
82
  }
@@ -77,39 +87,34 @@ class Array {
77
87
  }
78
88
 
79
89
  def at: idx {
80
- "Returns the element in the Array at a given index."
90
+ """
91
+ @idx Index for value to retrieve.
92
+ @return Value with the given index (if available), or @nil.
93
+
94
+ Returns the element in the @Array@ at a given index.
95
+ """
81
96
 
82
97
  ruby: '[] args: [idx]
83
98
  }
84
99
 
85
100
  def at: idx put: obj {
86
- "Inserts a given object at a given index (position) in the Array."
87
-
88
- ruby: '[]= args: [idx, obj]
89
- }
90
-
91
- def first {
92
- "Returns the first element in the Array."
93
- at: 0
94
- }
95
-
96
- def second {
97
- "Returns the second element in the Array"
98
- at: 1
99
- }
101
+ """
102
+ @idx Index to set a value for.
103
+ @obj Value (object) to be set at the given index.
104
+ @return @obj
100
105
 
101
- def third {
102
- "Returns the third element in the Array"
103
- at: 2
104
- }
106
+ Inserts a given object at a given index (position) in the Array.
107
+ """
105
108
 
106
- def fourth {
107
- "Returns the fourth element in the Array"
108
- at: 3
109
+ ruby: '[]= args: [idx, obj]
109
110
  }
110
111
 
111
112
  def each_with_index: block {
112
- "Iterate over all elements in Array. Calls a given Block with each element and its index."
113
+ """
114
+ @block @Block@ to be called with each element and its inde in the @Array@.
115
+
116
+ Iterate over all elements in Array. Calls a given Block with each element and its index.
117
+ """
113
118
 
114
119
  i = 0
115
120
  each: |x| {
@@ -119,12 +124,22 @@ class Array {
119
124
  }
120
125
 
121
126
  def index: item {
122
- "Returns the index of an item (or nil, if it isn't in the Array)."
127
+ """
128
+ @item Item/Value for which the index is requested within an @Array@.
129
+ @return Index of the value passed in within the @Array@, or @nil, if value not present.
130
+
131
+ Returns the index of an item (or nil, if it isn't in the @Array@).
132
+ """
123
133
  index(item)
124
134
  }
125
135
 
126
136
  def indices_of: item {
127
- "Returns an Array of all indices of this item. Empty Array if item does not occur."
137
+ """
138
+ @item Item/Value for which a list of indices is requested within an @Array@.
139
+ @return @Array@ of all indices for a given value within an @Array@ (possibly empty).
140
+
141
+ Returns an Array of all indices of this item. Empty Array if item does not occur.
142
+ """
128
143
 
129
144
  tmp = []
130
145
  each_with_index: |obj, idx| {
@@ -136,38 +151,61 @@ class Array {
136
151
  }
137
152
 
138
153
  def from: from to: to {
139
- "Returns sub-array starting at from: and going to to:"
154
+ """
155
+ @from Start index for sub-array.
156
+ @to End index ofr sub-array.
157
+
158
+ Returns sub-array starting at from: and going to to:
159
+ """
140
160
 
141
161
  if: (from < 0) then: {
142
- from = self size + from
162
+ from = size + from
143
163
  }
144
164
  if: (to < 0) then: {
145
- to = self size + to
165
+ to = size + to
146
166
  }
147
167
  subarr = []
148
168
  from upto: to do_each: |i| {
149
- subarr << (self at: i)
169
+ subarr << (at: i)
150
170
  }
151
171
  subarr
152
172
  }
153
173
 
154
174
  def last: count {
155
- "Returns new Array with last n elements specified."
175
+ """
176
+ @count Number of last elements to get from an @Array@.
177
+ @return @Array@ with up to @count size of last elements in @self.
178
+
179
+ Returns new Array with last n elements specified.
180
+ """
156
181
  last(count)
157
182
  }
158
183
 
159
184
  def any?: block {
160
- "Takes condition-block and returns true if any element meets it."
185
+ """
186
+ @block Predicate @Block@ to be called for each element until it returns @true for any one of them.
187
+ @return @true if any element in @self yields @true for @block, @false otherwise.
188
+
189
+ Takes condition-block and returns @true if any element meets it.
190
+ """
161
191
  any?(&block)
162
192
  }
163
193
 
164
194
  def all?: block {
165
- "Takes condition-block and returns true if all elements meet it."
195
+ """
196
+ @block Predicate @Block@ to be called for each element until it returns @false for any one of them.
197
+ @return @true if all elements in @self yield @true for @block, @false otherwise.
198
+
199
+ Takes condition-block and returns @true if all elements meet it.
200
+ """
166
201
  all?(&block)
167
202
  }
168
203
 
169
204
  def select: block {
170
205
  """
206
+ @block Predicate @Block@ to be used as filter.
207
+ @return @Array@ of all the elements for which @block doesn't yield @false or @nil.
208
+
171
209
  Returns a new Array with all the elements in self that yield a
172
210
  true-ish value when called with the given Block.
173
211
  """
@@ -183,7 +221,7 @@ class Array {
183
221
 
184
222
  def select_with_index: block {
185
223
  """
186
- Same as select, just gets also called with an additional argument
224
+ Same as select:, just gets also called with an additional argument
187
225
  for each element's index value.
188
226
  """
189
227