fancy 0.7.0 → 0.8.0
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.
- data/README.md +38 -86
- data/bin/fdoc +2 -22
- data/bin/fspec +8 -3
- data/bin/ifancy +1 -1
- data/boot/fancy_ext.rb +1 -0
- data/boot/fancy_ext/array.rb +19 -0
- data/boot/fancy_ext/class.rb +2 -4
- data/boot/fancy_ext/module.rb +2 -0
- data/boot/fancy_ext/object.rb +0 -17
- data/boot/rbx-compiler/compiler/ast/method_def.rb +0 -4
- data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +0 -7
- data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
- data/boot/rbx-compiler/parser/fancy_parser.c +1 -0
- data/doc/api/fancy.css +10 -1
- data/doc/api/fancy.jsonp +1 -1
- data/doc/api/fdoc.js +22 -9
- data/doc/api/octocat.png +0 -0
- data/doc/features.md +1 -2
- data/examples/actors.fy +1 -2
- data/examples/armstrong_numbers.fy +7 -3
- data/examples/blocks.fy +3 -3
- data/examples/distributing_proxy.fy +31 -0
- data/examples/future_sends.fy +15 -0
- data/examples/person.fy +1 -2
- data/lib/argv.fy +1 -7
- data/lib/array.fy +7 -11
- data/lib/block.fy +15 -0
- data/lib/boot.fy +4 -3
- data/lib/class.fy +354 -10
- data/lib/compiler.fy +1 -1
- data/lib/compiler/ast/assign.fy +4 -8
- data/lib/compiler/ast/async_send.fy +1 -2
- data/lib/compiler/ast/block.fy +5 -0
- data/lib/compiler/ast/class_def.fy +2 -1
- data/lib/compiler/ast/expression_list.fy +1 -2
- data/lib/compiler/ast/future_send.fy +1 -2
- data/lib/compiler/ast/identifier.fy +34 -17
- data/lib/compiler/ast/literals.fy +31 -19
- data/lib/compiler/ast/match.fy +5 -4
- data/lib/compiler/ast/message_send.fy +3 -5
- data/lib/compiler/ast/method_def.fy +0 -3
- data/lib/compiler/ast/range.fy +2 -4
- data/lib/compiler/ast/return.fy +2 -4
- data/lib/compiler/ast/script.fy +2 -4
- data/lib/compiler/ast/singleton_method_def.fy +0 -3
- data/lib/compiler/ast/string_interpolation.fy +2 -2
- data/lib/compiler/ast/super.fy +2 -4
- data/lib/compiler/ast/try_catch.fy +13 -9
- data/lib/compiler/ast/tuple_literal.fy +1 -2
- data/lib/compiler/compiler.fy +2 -2
- data/lib/compiler/stages.fy +3 -6
- data/lib/contracts.fy +89 -57
- data/lib/dynamic_slot_object.fy +21 -3
- data/lib/enumerable.fy +140 -4
- data/lib/enumerator.fy +1 -1
- data/lib/eval.fy +23 -9
- data/lib/exception.fy +16 -0
- data/lib/false_class.fy +36 -5
- data/lib/fancy_spec.fy +64 -34
- data/lib/fdoc.fy +85 -24
- data/lib/file.fy +19 -0
- data/lib/future.fy +4 -46
- data/lib/hash.fy +113 -0
- data/lib/integer.fy +25 -6
- data/lib/iteration.fy +3 -3
- data/lib/main.fy +5 -0
- data/lib/matchers.fy +79 -0
- data/lib/nil_class.fy +8 -0
- data/lib/object.fy +109 -18
- data/lib/option_parser.fy +118 -0
- data/lib/package/dependency.fy +4 -8
- data/lib/package/dependency_installer.fy +1 -1
- data/lib/package/handler.fy +6 -0
- data/lib/package/installer.fy +43 -16
- data/lib/package/list.fy +1 -2
- data/lib/package/specification.fy +5 -5
- data/lib/package/uninstaller.fy +9 -2
- data/lib/parser.fy +1 -3
- data/lib/parser/ext/ext.c +1 -0
- data/lib/parser/ext/lexer.lex +5 -0
- data/lib/parser/methods.fy +48 -46
- data/lib/proxies.fy +151 -0
- data/lib/rbx.fy +1 -0
- data/lib/rbx/actor.fy +16 -18
- data/lib/rbx/array.fy +18 -3
- data/lib/rbx/block.fy +1 -7
- data/lib/rbx/class.fy +54 -9
- data/lib/rbx/code_loader.fy +2 -5
- data/lib/rbx/compiled_method.fy +31 -0
- data/lib/rbx/debugger.fy +66 -0
- data/lib/rbx/directory.fy +8 -3
- data/lib/rbx/documentation.fy +1 -1
- data/lib/rbx/file.fy +22 -0
- data/lib/rbx/integer.fy +1 -1
- data/lib/rbx/match_data.fy +2 -1
- data/lib/rbx/method.fy +26 -0
- data/lib/rbx/object.fy +8 -3
- data/lib/rbx/regexp.fy +6 -3
- data/lib/rbx/string.fy +9 -1
- data/lib/rbx/stringio.fy +12 -0
- data/lib/rbx/symbol.fy +4 -0
- data/lib/stack.fy +1 -1
- data/lib/string.fy +34 -0
- data/lib/stringio.fy +1 -1
- data/lib/symbol.fy +6 -2
- data/lib/system.fy +15 -1
- data/lib/tuple.fy +5 -2
- data/lib/version.fy +1 -1
- data/ruby_lib/fdoc +2 -22
- data/tests/array.fy +3 -17
- data/tests/class.fy +312 -10
- data/tests/contracts.fy +51 -0
- data/tests/distributing_proxy.fy +28 -0
- data/tests/enumerable.fy +104 -1
- data/tests/exception.fy +35 -0
- data/tests/fixnum.fy +1 -1
- data/tests/hash.fy +81 -1
- data/tests/integer.fy +9 -0
- data/tests/matchers.fy +18 -0
- data/tests/method.fy +8 -14
- data/tests/object.fy +76 -2
- data/tests/option_parser.fy +80 -0
- data/tests/string.fy +21 -0
- data/tests/stringio.fy +1 -1
- data/tests/tuple.fy +1 -1
- metadata +21 -44
- data/examples/arithmetic.fy +0 -7
- data/examples/array.fy +0 -50
- data/examples/boolean.fy +0 -24
- data/examples/class.fy +0 -68
- data/examples/constant_access.fy +0 -15
- data/examples/default_args.fy +0 -20
- data/examples/define_methods.fy +0 -15
- data/examples/dynamic_output.fy +0 -15
- data/examples/empty_catch.fy +0 -4
- data/examples/exception.fy +0 -9
- data/examples/files.fy +0 -23
- data/examples/finally.fy +0 -5
- data/examples/future.fy +0 -30
- data/examples/future_composition.fy +0 -20
- data/examples/futures.fy +0 -9
- data/examples/game_of_life.fy +0 -148
- data/examples/html_generator.fy +0 -84
- data/examples/implicit_return.fy +0 -3
- data/examples/matchers.fy +0 -6
- data/examples/nested_try.fy +0 -9
- data/examples/numbers.fy +0 -12
- data/examples/rbx/and_or.fy +0 -7
- data/examples/rbx/blocks.fy +0 -22
- data/examples/rbx/classes.fy +0 -32
- data/examples/rbx/hello.fy +0 -8
- data/examples/rbx/include.fy +0 -12
- data/examples/rbx/inherit.fy +0 -11
- data/examples/rbx/methods.fy +0 -15
- data/examples/rbx/nested_classes.fy +0 -9
- data/examples/rbx/require.fy +0 -3
- data/examples/rbx/strings.fy +0 -5
- data/examples/require.fy +0 -7
- data/examples/return.fy +0 -13
- data/examples/singleton_methods.fy +0 -21
- data/examples/threads.fy +0 -18
- data/examples/tuple.fy +0 -8
- data/examples/webserver/webserver.fy +0 -15
- data/lib/proxy.fy +0 -86
- data/lib/thread_pool.fy +0 -102
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require: "lib/option_parser"
|
|
2
|
+
|
|
3
|
+
FancySpec describe: OptionParser with: {
|
|
4
|
+
it: "parses an option with no argument" when: {
|
|
5
|
+
parsed_option? = false
|
|
6
|
+
|
|
7
|
+
o = OptionParser new: @{
|
|
8
|
+
with: "--test" doc: "Do something" do: {
|
|
9
|
+
parsed_option? = true
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
parsed_option? is: false
|
|
14
|
+
o parse: ["foo", "bar", "--test", "baz"]
|
|
15
|
+
parsed_option? is: true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
it: "parses no option if none are passed" when: {
|
|
19
|
+
parsed_option? = false
|
|
20
|
+
o = OptionParser new: @{
|
|
21
|
+
with: "--foo [arg]" doc: "bla" do: |arg| {
|
|
22
|
+
parsed_option? = true
|
|
23
|
+
}
|
|
24
|
+
with: "--bar" doc: "more bla" do: {
|
|
25
|
+
parsed_option? = true
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
parsed_option? is: false
|
|
30
|
+
o parse: ["hello", "foo", "bar", "no expected options given!"]
|
|
31
|
+
parsed_option? is: false
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
it: "parses an option with an argument" when: {
|
|
35
|
+
parsed_option? = false
|
|
36
|
+
passed_args = []
|
|
37
|
+
|
|
38
|
+
o = OptionParser new: @{
|
|
39
|
+
with: "--my-val [arg]" doc: "gimme an argument!" do: |arg| {
|
|
40
|
+
parsed_option? = true
|
|
41
|
+
passed_args << (arg to_i)
|
|
42
|
+
}
|
|
43
|
+
with: "--my-other-val [arg]" doc: "gimme another argument!" do: |arg| {
|
|
44
|
+
parsed_option? = true
|
|
45
|
+
passed_args << (arg to_s * 2)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
parsed_option? is: false
|
|
50
|
+
passed_args is: []
|
|
51
|
+
o parse: ["foo", "1", "2", "bar", "--my-val", "42", "and", "--my-other-val", "42", "some", "more"]
|
|
52
|
+
parsed_option? is: true
|
|
53
|
+
passed_args size is: 2
|
|
54
|
+
passed_args includes?: 42 . is: true
|
|
55
|
+
passed_args includes?: "4242" . is: true
|
|
56
|
+
o parsed_options is: <["--my-val" => "42", "--my-other-val" => "42"]>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
it: "always prints the banner and --help message" with: 'print_help_info when: {
|
|
60
|
+
o = OptionParser new: @{
|
|
61
|
+
banner: "My Banner, yo"
|
|
62
|
+
}
|
|
63
|
+
out = StringIO new
|
|
64
|
+
let: '*stdout* be: out in: {
|
|
65
|
+
o print_help_info
|
|
66
|
+
out string is: "My Banner, yo\n\n --help Display this information\n"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
it: "removes options and their arguments after they have been parsed" with: 'remove_after_parsed: when: {
|
|
71
|
+
o = OptionParser new: @{
|
|
72
|
+
remove_after_parsed: true
|
|
73
|
+
with: "-value [arg]" doc: "" do: |arg| {}
|
|
74
|
+
with: "--my-flag" doc: "" do: {}
|
|
75
|
+
}
|
|
76
|
+
args = [1, "-value", "foo", "--my-flag", 2]
|
|
77
|
+
o parse: args
|
|
78
|
+
args is: [1, 2]
|
|
79
|
+
}
|
|
80
|
+
}
|
data/tests/string.fy
CHANGED
|
@@ -128,6 +128,7 @@ FancySpec describe: String with: {
|
|
|
128
128
|
|
|
129
129
|
it: "returns the character at a given index" with: '[] when: {
|
|
130
130
|
s = "hello"
|
|
131
|
+
s[-1] is: "o"
|
|
131
132
|
s[0] is: "h"
|
|
132
133
|
s[1] is: "e"
|
|
133
134
|
s[2] is: "l"
|
|
@@ -185,4 +186,24 @@ FancySpec describe: String with: {
|
|
|
185
186
|
"foobar" join: "-" . is: "f-o-o-b-a-r"
|
|
186
187
|
"" join: "-" . is: ""
|
|
187
188
|
}
|
|
189
|
+
|
|
190
|
+
it: "returns true if it's a multiline string and false otherwise" for: 'multiline? when: {
|
|
191
|
+
"foo\nbar" multiline? is: true
|
|
192
|
+
"\n" multiline? is: true
|
|
193
|
+
"\n\n" multiline? is: true
|
|
194
|
+
"foo bar" multiline? is: false
|
|
195
|
+
"" multiline? is: false
|
|
196
|
+
|
|
197
|
+
""" """ multiline? is: false
|
|
198
|
+
|
|
199
|
+
"""
|
|
200
|
+
""" multiline? is: true
|
|
201
|
+
|
|
202
|
+
"""
|
|
203
|
+
""" multiline? is: true
|
|
204
|
+
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
""" multiline? is: true
|
|
208
|
+
}
|
|
188
209
|
}
|
data/tests/stringio.fy
CHANGED
data/tests/tuple.fy
CHANGED
|
@@ -37,7 +37,7 @@ FancySpec describe: Tuple with: {
|
|
|
37
37
|
{ Tuple new: 2 } does_not raise: ArgumentError
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
it: "creates tuples dynamically" with: 'with_values when: {
|
|
40
|
+
it: "creates tuples dynamically" with: 'with_values: when: {
|
|
41
41
|
Tuple with_values: [1,2,3] . is: (1,2,3)
|
|
42
42
|
Tuple with_values: ["foo",'bar,42] . is: ("foo", 'bar, 42)
|
|
43
43
|
Tuple with_values: ('hello, 'world) . is: ('hello, 'world)
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fancy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 289844351982071926
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 8
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.8.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Christopher Bertels
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: ruby_lib
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2012-
|
|
18
|
+
date: 2012-08-29 00:00:00 Z
|
|
19
19
|
dependencies: []
|
|
20
20
|
|
|
21
21
|
description: |
|
|
@@ -66,6 +66,7 @@ files:
|
|
|
66
66
|
- lib/enumerable.fy
|
|
67
67
|
- lib/enumerator.fy
|
|
68
68
|
- lib/eval.fy
|
|
69
|
+
- lib/exception.fy
|
|
69
70
|
- lib/false_class.fy
|
|
70
71
|
- lib/fancy_spec.fy
|
|
71
72
|
- lib/fdoc.fy
|
|
@@ -79,13 +80,15 @@ files:
|
|
|
79
80
|
- lib/iteration.fy
|
|
80
81
|
- lib/kvo.fy
|
|
81
82
|
- lib/main.fy
|
|
83
|
+
- lib/matchers.fy
|
|
82
84
|
- lib/message_sink.fy
|
|
83
85
|
- lib/nil_class.fy
|
|
84
86
|
- lib/number.fy
|
|
85
87
|
- lib/object.fy
|
|
88
|
+
- lib/option_parser.fy
|
|
86
89
|
- lib/package.fy
|
|
87
90
|
- lib/parser.fy
|
|
88
|
-
- lib/
|
|
91
|
+
- lib/proxies.fy
|
|
89
92
|
- lib/range.fy
|
|
90
93
|
- lib/rbx.fy
|
|
91
94
|
- lib/set.fy
|
|
@@ -95,7 +98,6 @@ files:
|
|
|
95
98
|
- lib/struct.fy
|
|
96
99
|
- lib/symbol.fy
|
|
97
100
|
- lib/system.fy
|
|
98
|
-
- lib/thread_pool.fy
|
|
99
101
|
- lib/true_class.fy
|
|
100
102
|
- lib/tuple.fy
|
|
101
103
|
- lib/vars.fy
|
|
@@ -120,8 +122,10 @@ files:
|
|
|
120
122
|
- lib/rbx/block.fy
|
|
121
123
|
- lib/rbx/class.fy
|
|
122
124
|
- lib/rbx/code_loader.fy
|
|
125
|
+
- lib/rbx/compiled_method.fy
|
|
123
126
|
- lib/rbx/console.fy
|
|
124
127
|
- lib/rbx/date.fy
|
|
128
|
+
- lib/rbx/debugger.fy
|
|
125
129
|
- lib/rbx/directory.fy
|
|
126
130
|
- lib/rbx/documentation.fy
|
|
127
131
|
- lib/rbx/environment_variables.fy
|
|
@@ -183,7 +187,9 @@ files:
|
|
|
183
187
|
- tests/assignment.fy
|
|
184
188
|
- tests/block.fy
|
|
185
189
|
- tests/class.fy
|
|
190
|
+
- tests/contracts.fy
|
|
186
191
|
- tests/control_flow.fy
|
|
192
|
+
- tests/distributing_proxy.fy
|
|
187
193
|
- tests/documentation.fy
|
|
188
194
|
- tests/dynamic_key_hash.fy
|
|
189
195
|
- tests/dynamic_slot_object.fy
|
|
@@ -196,11 +202,14 @@ files:
|
|
|
196
202
|
- tests/future.fy
|
|
197
203
|
- tests/hash.fy
|
|
198
204
|
- tests/html.fy
|
|
205
|
+
- tests/integer.fy
|
|
199
206
|
- tests/kvo.fy
|
|
207
|
+
- tests/matchers.fy
|
|
200
208
|
- tests/method.fy
|
|
201
209
|
- tests/nil_class.fy
|
|
202
210
|
- tests/number.fy
|
|
203
211
|
- tests/object.fy
|
|
212
|
+
- tests/option_parser.fy
|
|
204
213
|
- tests/pattern_matching.fy
|
|
205
214
|
- tests/range.fy
|
|
206
215
|
- tests/set.fy
|
|
@@ -222,68 +231,33 @@ files:
|
|
|
222
231
|
- examples/actors_primitive.fy
|
|
223
232
|
- examples/actors_ring.fy
|
|
224
233
|
- examples/argv.fy
|
|
225
|
-
- examples/arithmetic.fy
|
|
226
234
|
- examples/armstrong_numbers.fy
|
|
227
|
-
- examples/array.fy
|
|
228
235
|
- examples/async_send.fy
|
|
229
236
|
- examples/blocks.fy
|
|
230
|
-
- examples/boolean.fy
|
|
231
237
|
- examples/call_with_receiver.fy
|
|
232
|
-
- examples/class.fy
|
|
233
238
|
- examples/closures.fy
|
|
234
|
-
- examples/
|
|
235
|
-
- examples/default_args.fy
|
|
236
|
-
- examples/define_methods.fy
|
|
239
|
+
- examples/distributing_proxy.fy
|
|
237
240
|
- examples/documentation.fy
|
|
238
241
|
- examples/documentation_formatters.fy
|
|
239
|
-
- examples/dynamic_output.fy
|
|
240
242
|
- examples/echo.fy
|
|
241
|
-
- examples/empty_catch.fy
|
|
242
|
-
- examples/exception.fy
|
|
243
243
|
- examples/factorial.fy
|
|
244
244
|
- examples/fibonacci.fy
|
|
245
|
-
- examples/
|
|
246
|
-
- examples/finally.fy
|
|
247
|
-
- examples/future.fy
|
|
248
|
-
- examples/future_composition.fy
|
|
249
|
-
- examples/futures.fy
|
|
250
|
-
- examples/game_of_life.fy
|
|
245
|
+
- examples/future_sends.fy
|
|
251
246
|
- examples/hashes.fy
|
|
252
247
|
- examples/hello_world.fy
|
|
253
|
-
- examples/html_generator.fy
|
|
254
|
-
- examples/implicit_return.fy
|
|
255
|
-
- examples/matchers.fy
|
|
256
248
|
- examples/methods.fy
|
|
257
249
|
- examples/nested_classes.fy
|
|
258
|
-
- examples/nested_try.fy
|
|
259
|
-
- examples/numbers.fy
|
|
260
250
|
- examples/pattern_matching.fy
|
|
261
251
|
- examples/person.fy
|
|
262
252
|
- examples/regex.fy
|
|
263
|
-
- examples/require.fy
|
|
264
253
|
- examples/retry.fy
|
|
265
|
-
- examples/return.fy
|
|
266
254
|
- examples/ruby_require.fy
|
|
267
255
|
- examples/ruby_send.fy
|
|
268
|
-
- examples/singleton_methods.fy
|
|
269
256
|
- examples/struct.fy
|
|
270
257
|
- examples/stupid_quicksort.fy
|
|
271
|
-
- examples/threads.fy
|
|
272
|
-
- examples/tuple.fy
|
|
273
258
|
- examples/project-euler/01.fy
|
|
274
259
|
- examples/project-euler/02.fy
|
|
275
260
|
- examples/project-euler/28.fy
|
|
276
|
-
- examples/rbx/and_or.fy
|
|
277
|
-
- examples/rbx/blocks.fy
|
|
278
|
-
- examples/rbx/classes.fy
|
|
279
|
-
- examples/rbx/hello.fy
|
|
280
|
-
- examples/rbx/include.fy
|
|
281
|
-
- examples/rbx/inherit.fy
|
|
282
|
-
- examples/rbx/methods.fy
|
|
283
|
-
- examples/rbx/nested_classes.fy
|
|
284
|
-
- examples/rbx/require.fy
|
|
285
|
-
- examples/rbx/strings.fy
|
|
286
|
-
- examples/webserver/webserver.fy
|
|
287
261
|
- doc/features.md
|
|
288
262
|
- doc/api/fancy.css
|
|
289
263
|
- doc/api/fancy.jsonp
|
|
@@ -291,6 +265,7 @@ files:
|
|
|
291
265
|
- doc/api/index.html
|
|
292
266
|
- doc/api/jquery-ui.min.js
|
|
293
267
|
- doc/api/jquery.tools.min.js
|
|
268
|
+
- doc/api/octocat.png
|
|
294
269
|
- doc/api/themeswitchertool.js
|
|
295
270
|
- doc/api/underscore-min.js
|
|
296
271
|
- boot/code_loader.rb
|
|
@@ -299,6 +274,7 @@ files:
|
|
|
299
274
|
- boot/load.rb
|
|
300
275
|
- boot/README
|
|
301
276
|
- boot/rsexp_pretty_printer.rb
|
|
277
|
+
- boot/fancy_ext/array.rb
|
|
302
278
|
- boot/fancy_ext/block_env.rb
|
|
303
279
|
- boot/fancy_ext/bootstrap.rb
|
|
304
280
|
- boot/fancy_ext/class.rb
|
|
@@ -376,9 +352,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
376
352
|
requirements: []
|
|
377
353
|
|
|
378
354
|
rubyforge_project: fancy
|
|
379
|
-
rubygems_version: 1.8.
|
|
355
|
+
rubygems_version: 1.8.24
|
|
380
356
|
signing_key:
|
|
381
357
|
specification_version: 3
|
|
382
358
|
summary: The Fancy Programming Language
|
|
383
359
|
test_files: []
|
|
384
360
|
|
|
361
|
+
has_rdoc: false
|
data/examples/arithmetic.fy
DELETED
data/examples/array.fy
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# array.fy
|
|
2
|
-
# Examples of fancy Arrays
|
|
3
|
-
|
|
4
|
-
# create an array
|
|
5
|
-
arr = [1,2,3,4,5,6]
|
|
6
|
-
|
|
7
|
-
# print each element squared
|
|
8
|
-
arr each: @{ squared println }
|
|
9
|
-
|
|
10
|
-
# display each element with its index in the array
|
|
11
|
-
arr each_with_index: |x i| {
|
|
12
|
-
"Index " ++ i ++ " -> " ++ x println
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
# print the array of squared elements
|
|
16
|
-
arr map: 'squared . inspect println
|
|
17
|
-
|
|
18
|
-
# print the array of doubled elements
|
|
19
|
-
arr map: 'doubled . inspect println
|
|
20
|
-
|
|
21
|
-
# print array of all elements smaller than 4
|
|
22
|
-
arr select: @{ < 4 } . inspect println
|
|
23
|
-
|
|
24
|
-
# print array of all elements that are not smaller than 4
|
|
25
|
-
arr reject: @{ < 4 } . inspect println
|
|
26
|
-
|
|
27
|
-
# prints: [5, 6]
|
|
28
|
-
arr take_while: @{ < 5 } . inspect println
|
|
29
|
-
|
|
30
|
-
"testing reduce:init_val: " print
|
|
31
|
-
arr reduce: |acc x| { acc * x } init_val: 1 . println # same as: 1*1*2*3*4*5*6
|
|
32
|
-
|
|
33
|
-
"testing any?: " print
|
|
34
|
-
arr any?: @{ > 3 } . println # prints: true
|
|
35
|
-
|
|
36
|
-
"testing all?: " print
|
|
37
|
-
arr all?: @{ < 7 } . println # prints: true
|
|
38
|
-
|
|
39
|
-
"testing from:to: " print
|
|
40
|
-
arr [[3,5]] . inspect println # prints: [4, 5, 6]
|
|
41
|
-
|
|
42
|
-
# some other handy methods
|
|
43
|
-
"testing size: " print
|
|
44
|
-
arr size println # prints: 6
|
|
45
|
-
|
|
46
|
-
"testing to_s: " print
|
|
47
|
-
arr to_s println # prints: 123456
|
|
48
|
-
|
|
49
|
-
"testing inspect: " print
|
|
50
|
-
arr inspect println # prints: [1, 2, 3, 4, 5, 6]
|
data/examples/boolean.fy
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# boolean.fy
|
|
2
|
-
# Example of boolean expressions and logical operations in fancy
|
|
3
|
-
|
|
4
|
-
true and: true . println # true
|
|
5
|
-
true and: nil . println # nil
|
|
6
|
-
nil and: nil . println # nil
|
|
7
|
-
|
|
8
|
-
true or: true . println # true
|
|
9
|
-
true or: nil . println # true
|
|
10
|
-
nil or: nil . println # nil
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"--------------" println
|
|
14
|
-
|
|
15
|
-
# won't print string
|
|
16
|
-
nil if_true: {
|
|
17
|
-
"this should _not_ be displayed" println
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
# will print string
|
|
21
|
-
nil if_false: {
|
|
22
|
-
"this _should_ be displayed" println
|
|
23
|
-
}
|
|
24
|
-
|
data/examples/class.fy
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# class.fy
|
|
2
|
-
# Example of fancy's classes mechanism
|
|
3
|
-
|
|
4
|
-
class Bar {
|
|
5
|
-
def initialize {
|
|
6
|
-
Console println: "In Bar constructor!"
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
def say_hello: name {
|
|
10
|
-
Console print: "Hello, "
|
|
11
|
-
Console println: name
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
class Foo : Bar {
|
|
16
|
-
def initialize: name {
|
|
17
|
-
Console println: "gonna set @name"
|
|
18
|
-
@name = name
|
|
19
|
-
}
|
|
20
|
-
def say_hello {
|
|
21
|
-
Console print: "Hello, "
|
|
22
|
-
Console println: @name
|
|
23
|
-
{ @block call } if: @block
|
|
24
|
-
}
|
|
25
|
-
def on_hello_do: block {
|
|
26
|
-
@block = block
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
bar = Bar new
|
|
31
|
-
bar say_hello: "Chris"
|
|
32
|
-
|
|
33
|
-
foo = Foo new: "Chris from Constructor"
|
|
34
|
-
foo say_hello
|
|
35
|
-
foo on_hello_do: {
|
|
36
|
-
Console println: "Call me when calling on_hello! :)"
|
|
37
|
-
}
|
|
38
|
-
foo say_hello
|
|
39
|
-
|
|
40
|
-
foo class println # print the class of foo
|
|
41
|
-
|
|
42
|
-
# define a singleton method on foo object
|
|
43
|
-
foo define_singleton_method: "foo!" with: {
|
|
44
|
-
"In foo method :D" println
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
foo foo!
|
|
48
|
-
|
|
49
|
-
# define a 'normal' method on Foo class
|
|
50
|
-
# (instance method for all instances of Foo)
|
|
51
|
-
foo class define_method: "foo_for_all:" with: |x| {
|
|
52
|
-
"In foo_for_all method (defined for all instances of Foo class)" println
|
|
53
|
-
"Got argument: " ++ x println
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
foo2 = Foo new
|
|
57
|
-
foo2 foo_for_all: "hello, test! :)"
|
|
58
|
-
foo foo_for_all: "hello, test (again)! :)"
|
|
59
|
-
|
|
60
|
-
# define a class method on Foo class
|
|
61
|
-
# it's the same as calling 'define_singleton_method:with:' on class
|
|
62
|
-
foo class define_class_method: "cool_class_method:" with: |arg| {
|
|
63
|
-
"In class method for Foo! Argument given: " ++ arg println
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
# the following is the same as:
|
|
67
|
-
# foo class cool_class_method: "Some argument string"
|
|
68
|
-
Foo cool_class_method: "Some argument string"
|