fancy 0.3.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.
Files changed (242) hide show
  1. data/AUTHORS +7 -0
  2. data/LICENSE +19 -0
  3. data/README +173 -0
  4. data/Rakefile +255 -0
  5. data/bin/fancy +40 -0
  6. data/bin/fdoc +23 -0
  7. data/bin/fyi +22 -0
  8. data/bin/ifancy +46 -0
  9. data/boot/README +12 -0
  10. data/boot/code_loader.rb +165 -0
  11. data/boot/compile.fy +3 -0
  12. data/boot/fancy_ext.rb +13 -0
  13. data/boot/fancy_ext/block_env.rb +29 -0
  14. data/boot/fancy_ext/class.rb +26 -0
  15. data/boot/fancy_ext/kernel.rb +12 -0
  16. data/boot/fancy_ext/module.rb +89 -0
  17. data/boot/fancy_ext/object.rb +34 -0
  18. data/boot/fancy_ext/string_helper.rb +10 -0
  19. data/boot/load.rb +72 -0
  20. data/boot/rbx-compiler/README +12 -0
  21. data/boot/rbx-compiler/compiler.rb +24 -0
  22. data/boot/rbx-compiler/compiler/ast.rb +23 -0
  23. data/boot/rbx-compiler/compiler/ast/README +11 -0
  24. data/boot/rbx-compiler/compiler/ast/array_literal.rb +13 -0
  25. data/boot/rbx-compiler/compiler/ast/assign.rb +57 -0
  26. data/boot/rbx-compiler/compiler/ast/block.rb +70 -0
  27. data/boot/rbx-compiler/compiler/ast/class_def.rb +35 -0
  28. data/boot/rbx-compiler/compiler/ast/expression_list.rb +57 -0
  29. data/boot/rbx-compiler/compiler/ast/hash_literal.rb +11 -0
  30. data/boot/rbx-compiler/compiler/ast/identifier.rb +120 -0
  31. data/boot/rbx-compiler/compiler/ast/match.rb +81 -0
  32. data/boot/rbx-compiler/compiler/ast/message_send.rb +71 -0
  33. data/boot/rbx-compiler/compiler/ast/method_def.rb +116 -0
  34. data/boot/rbx-compiler/compiler/ast/node.rb +6 -0
  35. data/boot/rbx-compiler/compiler/ast/range_literal.rb +22 -0
  36. data/boot/rbx-compiler/compiler/ast/require.rb +20 -0
  37. data/boot/rbx-compiler/compiler/ast/return.rb +29 -0
  38. data/boot/rbx-compiler/compiler/ast/ruby_args.rb +35 -0
  39. data/boot/rbx-compiler/compiler/ast/script.rb +56 -0
  40. data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +39 -0
  41. data/boot/rbx-compiler/compiler/ast/string_literal.rb +14 -0
  42. data/boot/rbx-compiler/compiler/ast/super.rb +25 -0
  43. data/boot/rbx-compiler/compiler/ast/try_catch_block.rb +220 -0
  44. data/boot/rbx-compiler/compiler/ast/tuple_literal.rb +33 -0
  45. data/boot/rbx-compiler/compiler/command.rb +39 -0
  46. data/boot/rbx-compiler/compiler/compiler.rb +83 -0
  47. data/boot/rbx-compiler/compiler/stages.rb +99 -0
  48. data/boot/rbx-compiler/parser.rb +2 -0
  49. data/boot/rbx-compiler/parser/README +15 -0
  50. data/boot/rbx-compiler/parser/Rakefile +54 -0
  51. data/boot/rbx-compiler/parser/extconf.rb +3 -0
  52. data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
  53. data/boot/rbx-compiler/parser/fancy_parser.c +46 -0
  54. data/boot/rbx-compiler/parser/fancy_parser.h +8 -0
  55. data/boot/rbx-compiler/parser/lexer.lex +180 -0
  56. data/boot/rbx-compiler/parser/parser.rb +356 -0
  57. data/boot/rbx-compiler/parser/parser.y +711 -0
  58. data/boot/rsexp_pretty_printer.rb +76 -0
  59. data/doc/api/fancy.css +93 -0
  60. data/doc/api/fancy.jsonp +1 -0
  61. data/doc/api/fdoc.js +187 -0
  62. data/doc/api/index.html +57 -0
  63. data/doc/api/underscore-min.js +18 -0
  64. data/doc/features.md +228 -0
  65. data/examples/argv.fy +8 -0
  66. data/examples/arithmetic.fy +7 -0
  67. data/examples/armstrong_numbers.fy +33 -0
  68. data/examples/array.fy +52 -0
  69. data/examples/blocks.fy +15 -0
  70. data/examples/boolean.fy +24 -0
  71. data/examples/call_with_receiver.fy +9 -0
  72. data/examples/class.fy +68 -0
  73. data/examples/closures.fy +24 -0
  74. data/examples/constant_access.fy +15 -0
  75. data/examples/default_args.fy +17 -0
  76. data/examples/define_methods.fy +15 -0
  77. data/examples/documentation.fy +57 -0
  78. data/examples/documentation_formatters.fy +25 -0
  79. data/examples/echo.fy +16 -0
  80. data/examples/empty_catch.fy +4 -0
  81. data/examples/exception.fy +9 -0
  82. data/examples/factorial.fy +12 -0
  83. data/examples/fibonacci.fy +16 -0
  84. data/examples/files.fy +23 -0
  85. data/examples/finally.fy +5 -0
  86. data/examples/game_of_life.fy +148 -0
  87. data/examples/hashes.fy +7 -0
  88. data/examples/hello_world.fy +6 -0
  89. data/examples/html_generator.fy +54 -0
  90. data/examples/implicit_return.fy +3 -0
  91. data/examples/matchers.fy +6 -0
  92. data/examples/methods.fy +29 -0
  93. data/examples/nested_classes.fy +27 -0
  94. data/examples/nested_try.fy +9 -0
  95. data/examples/numbers.fy +12 -0
  96. data/examples/pattern_matching.fy +40 -0
  97. data/examples/person.fy +65 -0
  98. data/examples/project-euler/01.fy +8 -0
  99. data/examples/project-euler/02.fy +21 -0
  100. data/examples/project-euler/28.fy +33 -0
  101. data/examples/rbx/and_or.fy +7 -0
  102. data/examples/rbx/blocks.fy +22 -0
  103. data/examples/rbx/classes.fy +32 -0
  104. data/examples/rbx/hello.fy +8 -0
  105. data/examples/rbx/include.fy +12 -0
  106. data/examples/rbx/inherit.fy +11 -0
  107. data/examples/rbx/methods.fy +15 -0
  108. data/examples/rbx/nested_classes.fy +9 -0
  109. data/examples/rbx/require.fy +3 -0
  110. data/examples/rbx/strings.fy +5 -0
  111. data/examples/regex.fy +7 -0
  112. data/examples/require.fy +7 -0
  113. data/examples/retry.fy +12 -0
  114. data/examples/return.fy +13 -0
  115. data/examples/ruby_require.fy +7 -0
  116. data/examples/ruby_send.fy +3 -0
  117. data/examples/singleton_methods.fy +21 -0
  118. data/examples/stupid_quicksort.fy +12 -0
  119. data/examples/threads.fy +18 -0
  120. data/examples/tuple.fy +8 -0
  121. data/examples/webserver/webserver.fy +18 -0
  122. data/lib/argv.fy +36 -0
  123. data/lib/array.fy +207 -0
  124. data/lib/block.fy +88 -0
  125. data/lib/boot.fy +41 -0
  126. data/lib/class.fy +106 -0
  127. data/lib/compiler.fy +14 -0
  128. data/lib/compiler/ast.fy +40 -0
  129. data/lib/compiler/ast/assign.fy +96 -0
  130. data/lib/compiler/ast/block.fy +84 -0
  131. data/lib/compiler/ast/class_def.fy +33 -0
  132. data/lib/compiler/ast/expression_list.fy +47 -0
  133. data/lib/compiler/ast/identifier.fy +113 -0
  134. data/lib/compiler/ast/literals.fy +122 -0
  135. data/lib/compiler/ast/match.fy +88 -0
  136. data/lib/compiler/ast/message_send.fy +110 -0
  137. data/lib/compiler/ast/method_def.fy +90 -0
  138. data/lib/compiler/ast/node.fy +7 -0
  139. data/lib/compiler/ast/range.fy +16 -0
  140. data/lib/compiler/ast/require.fy +15 -0
  141. data/lib/compiler/ast/return.fy +23 -0
  142. data/lib/compiler/ast/script.fy +52 -0
  143. data/lib/compiler/ast/singleton_method_def.fy +35 -0
  144. data/lib/compiler/ast/super.fy +17 -0
  145. data/lib/compiler/ast/try_catch.fy +176 -0
  146. data/lib/compiler/ast/tuple_literal.fy +34 -0
  147. data/lib/compiler/command.fy +51 -0
  148. data/lib/compiler/compiler.fy +73 -0
  149. data/lib/compiler/stages.fy +81 -0
  150. data/lib/directory.fy +17 -0
  151. data/lib/documentation.fy +115 -0
  152. data/lib/enumerable.fy +269 -0
  153. data/lib/eval.fy +31 -0
  154. data/lib/fancy_spec.fy +202 -0
  155. data/lib/fdoc.fy +359 -0
  156. data/lib/fdoc_hook.fy +10 -0
  157. data/lib/file.fy +54 -0
  158. data/lib/hash.fy +56 -0
  159. data/lib/main.fy +80 -0
  160. data/lib/method.fy +22 -0
  161. data/lib/nil_class.fy +56 -0
  162. data/lib/number.fy +87 -0
  163. data/lib/object.fy +170 -0
  164. data/lib/package.fy +61 -0
  165. data/lib/package/dependency.fy +24 -0
  166. data/lib/package/installer.fy +180 -0
  167. data/lib/package/specification.fy +55 -0
  168. data/lib/package/uninstaller.fy +15 -0
  169. data/lib/parser.fy +4 -0
  170. data/lib/parser/ext/README +15 -0
  171. data/lib/parser/ext/ext.c +42 -0
  172. data/lib/parser/ext/ext.h +8 -0
  173. data/lib/parser/ext/extconf.rb +3 -0
  174. data/lib/parser/ext/lexer.lex +187 -0
  175. data/lib/parser/ext/parser.y +744 -0
  176. data/lib/parser/methods.fy +297 -0
  177. data/lib/rbx.fy +37 -0
  178. data/lib/rbx/array.fy +237 -0
  179. data/lib/rbx/bignum.fy +23 -0
  180. data/lib/rbx/block.fy +9 -0
  181. data/lib/rbx/class.fy +129 -0
  182. data/lib/rbx/code_loader.fy +192 -0
  183. data/lib/rbx/console.fy +63 -0
  184. data/lib/rbx/directory.fy +46 -0
  185. data/lib/rbx/documentation.fy +64 -0
  186. data/lib/rbx/environment_variables.fy +3 -0
  187. data/lib/rbx/exception.fy +30 -0
  188. data/lib/rbx/false_class.fy +58 -0
  189. data/lib/rbx/fiber.fy +25 -0
  190. data/lib/rbx/file.fy +191 -0
  191. data/lib/rbx/fixnum.fy +25 -0
  192. data/lib/rbx/float.fy +14 -0
  193. data/lib/rbx/hash.fy +38 -0
  194. data/lib/rbx/integer.fy +15 -0
  195. data/lib/rbx/io.fy +30 -0
  196. data/lib/rbx/match_data.fy +9 -0
  197. data/lib/rbx/method.fy +22 -0
  198. data/lib/rbx/name_error.fy +3 -0
  199. data/lib/rbx/no_method_error.fy +15 -0
  200. data/lib/rbx/object.fy +117 -0
  201. data/lib/rbx/range.fy +15 -0
  202. data/lib/rbx/regexp.fy +9 -0
  203. data/lib/rbx/string.fy +63 -0
  204. data/lib/rbx/symbol.fy +12 -0
  205. data/lib/rbx/system.fy +37 -0
  206. data/lib/rbx/tcp_server.fy +6 -0
  207. data/lib/rbx/tcp_socket.fy +7 -0
  208. data/lib/rbx/thread.fy +75 -0
  209. data/lib/rbx/tuple.fy +37 -0
  210. data/lib/set.fy +61 -0
  211. data/lib/stack.fy +51 -0
  212. data/lib/string.fy +58 -0
  213. data/lib/struct.fy +13 -0
  214. data/lib/symbol.fy +23 -0
  215. data/lib/true_class.fy +43 -0
  216. data/lib/tuple.fy +68 -0
  217. data/lib/version.fy +6 -0
  218. data/tests/argv.fy +13 -0
  219. data/tests/array.fy +343 -0
  220. data/tests/assignment.fy +53 -0
  221. data/tests/block.fy +103 -0
  222. data/tests/class.fy +409 -0
  223. data/tests/control_flow.fy +79 -0
  224. data/tests/documentation.fy +24 -0
  225. data/tests/exception.fy +115 -0
  226. data/tests/file.fy +86 -0
  227. data/tests/hash.fy +101 -0
  228. data/tests/method.fy +131 -0
  229. data/tests/nil_class.fy +55 -0
  230. data/tests/number.fy +128 -0
  231. data/tests/object.fy +125 -0
  232. data/tests/parsing/sexp.fy +50 -0
  233. data/tests/pattern_matching.fy +82 -0
  234. data/tests/range.fy +11 -0
  235. data/tests/set.fy +10 -0
  236. data/tests/stack.fy +22 -0
  237. data/tests/string.fy +102 -0
  238. data/tests/symbol.fy +17 -0
  239. data/tests/true_class.fy +63 -0
  240. data/tests/tuple.fy +21 -0
  241. data/tools/fancy-mode.el +63 -0
  242. metadata +321 -0
data/examples/argv.fy ADDED
@@ -0,0 +1,8 @@
1
+ # argv.fy
2
+ # Example of fancy's interface for command line arguments
3
+
4
+ "This will always get printed, even when required from another file" println
5
+
6
+ if: (ARGV[0] == __FILE__) then: {
7
+ "This will get printed, if this file is directly run with fancy" println
8
+ }
@@ -0,0 +1,7 @@
1
+ # arithmetic.fy
2
+ # Example of some basic arithmetic operations in fancy
3
+
4
+ 23 + 32432.32 println
5
+ 324432.432 - 32432.4324 println
6
+ 32432 * 432.32 println
7
+ 432 / 12319 println
@@ -0,0 +1,33 @@
1
+ # armstrong_numbers.fy
2
+ # Calculates & outputs all Armstrong Numbers between 0 and 10000.
3
+ # See http://en.wikipedia.org/wiki/Narcissistic_number for more
4
+ # information.
5
+
6
+ class Fixnum {
7
+ def decimals {
8
+ """Returns all decimals of a Number as an Array.
9
+ E.g. 123 decimals # => [1,2,3]"""
10
+
11
+ decimals = []
12
+ tmp = self
13
+ while: { tmp >= 10 } do: {
14
+ decimals << (tmp modulo: 10)
15
+ tmp = (tmp div: 10)
16
+ }
17
+ decimals << tmp
18
+ decimals
19
+ }
20
+
21
+ def armstrong? {
22
+ "Indicates, if a Number is a Armstrong Number."
23
+
24
+ decimals = self decimals
25
+ n_decimals = decimals size
26
+ decimals map: |x| { x ** n_decimals } . sum == self
27
+ }
28
+ }
29
+
30
+ # output alls Armstrong Numbers between 0 and 10000
31
+ 0 upto: 10000 do_each: |i| {
32
+ { i println } if: $ i armstrong?
33
+ }
data/examples/array.fy ADDED
@@ -0,0 +1,52 @@
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: |x| {
9
+ x squared println
10
+ }
11
+
12
+ # display each element with its index in the array
13
+ arr each_with_index: |x i| {
14
+ "Index " ++ i ++ " -> " ++ x println
15
+ }
16
+
17
+ # print the array of squared elements
18
+ arr map: 'squared . inspect println
19
+
20
+ # print the array of doubled elements
21
+ arr map: 'doubled . inspect println
22
+
23
+ # print array of all elements smaller than 4
24
+ arr select: |x| { x < 4 } . inspect println
25
+
26
+ # print array of all elements that are not smaller than 4
27
+ arr reject: |x| { x < 4 } . inspect println
28
+
29
+ # prints: [5, 6]
30
+ arr take_while: |x| { x < 5 } . inspect println
31
+
32
+ "testing reduce:init_val: " print
33
+ arr reduce: |acc x| { acc * x } init_val: 1 . println # same as: 1*1*2*3*4*5*6
34
+
35
+ "testing any?: " print
36
+ arr any?: |x| { x > 3 } . println # prints: true
37
+
38
+ "testing all?: " print
39
+ arr all?: |x| { x < 7 } . println # prints: true
40
+
41
+ "testing from:to: " print
42
+ arr [[3,5]] . inspect println # prints: [4, 5, 6]
43
+
44
+ # some other handy methods
45
+ "testing size: " print
46
+ arr size println # prints: 6
47
+
48
+ "testing to_s: " print
49
+ arr to_s println # prints: 123456
50
+
51
+ "testing inspect: " print
52
+ arr inspect println # prints: [1, 2, 3, 4, 5, 6] : Array
@@ -0,0 +1,15 @@
1
+ # blocks.fy
2
+ # Examples of fancy code blocks
3
+
4
+ x = { Console println: "Println from within block!" }
5
+ x call # calls x and prints: "Println from within block!"
6
+
7
+ y = |x y| { Console println: $ x + y }
8
+ y call: [2, 3] # calls y and prints: 5
9
+
10
+ # prints numbers 0 to 20
11
+ zahl = 0
12
+ while: { zahl <= 20 } do: {
13
+ Console println: zahl
14
+ zahl = zahl + 1
15
+ }
@@ -0,0 +1,24 @@
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
+
@@ -0,0 +1,9 @@
1
+ block = { self foo }
2
+
3
+ class Foo {
4
+ def foo {
5
+ "in Foo#foo!" println
6
+ }
7
+ }
8
+
9
+ block call_with_receiver: (Foo new)
data/examples/class.fy ADDED
@@ -0,0 +1,68 @@
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"
@@ -0,0 +1,24 @@
1
+ # closure.fy
2
+ # Example of closures in fancy
3
+
4
+ # method that returns a closure
5
+ def create_counter: number {
6
+ closure = {
7
+ number = number + 1
8
+ }
9
+ closure
10
+ }
11
+
12
+ # create a counter from 100 upwards
13
+ closure = create_counter: 100
14
+ # this will print numbers 100 - 120
15
+ 20 times: {
16
+ Console println: $ closure call
17
+ }
18
+
19
+ # create a counter from 500 upwards
20
+ closure = create_counter: 500
21
+ # this will print numbers 500 - 510
22
+ 10 times: {
23
+ Console println: $ closure call
24
+ }
@@ -0,0 +1,15 @@
1
+ class Foo {
2
+ class Bar {
3
+ def self name { 'bar }
4
+ }
5
+ }
6
+
7
+ Foo Bar name println
8
+
9
+ class Foo Baz { }
10
+
11
+ Foo Baz == Foo::Baz println
12
+
13
+ def Foo Baz name { 'baz }
14
+
15
+ Foo Baz name println
@@ -0,0 +1,17 @@
1
+ # default_args.fy
2
+ # Example of fancy's default arguments
3
+
4
+ def arg1: arg1 arg2: arg2 ("default_arg2") arg3: arg3 ("default_arg3") {
5
+ "arguments are: " println
6
+ arg1 println
7
+ arg2 println
8
+ arg3 println
9
+ }
10
+
11
+ arg1: "hello" arg2: "world" arg3: "how are you?"
12
+
13
+ Console newline
14
+ arg1: "hello" arg2: "world"
15
+
16
+ Console newline
17
+ arg1: "hello"
@@ -0,0 +1,15 @@
1
+ arr = [1,2,3]
2
+ arr define_singleton_method: "foo" with: {
3
+ "in foo!" println
4
+ self inspect println
5
+ }
6
+
7
+ arr send: 'foo
8
+
9
+ arr undefine_singleton_method: "foo"
10
+
11
+ try {
12
+ arr send: 'foo
13
+ } catch NoMethodError => e {
14
+ e println
15
+ }
@@ -0,0 +1,57 @@
1
+ # documentation.fy
2
+ # Example about fancys built-in documentation facilities
3
+
4
+ class Foo {
5
+
6
+ """
7
+ If first expression in a class body is an string literal
8
+ it is used as documentation.
9
+ """
10
+
11
+ m = def foo: x bar: y (22) {
12
+ "Prints its own documentation."
13
+ "TODO: obtain methodContext and print own documentation" println
14
+ }
15
+ m documentation println
16
+
17
+ }
18
+
19
+ foo = Foo new
20
+
21
+ foo method: 'foo:bar: . documentation println
22
+ foo method: 'foo: . documentation println
23
+
24
+ def foo bar: n {
25
+ "A singleton method"
26
+ n println
27
+ }
28
+
29
+ foo method: 'bar: . documentation println
30
+
31
+ Foo instance_method: 'foo: . documentation println
32
+
33
+ Foo documentation println
34
+
35
+ block = |a, b| {
36
+ "A block can also have a documentation string, just like methods"
37
+ a + b
38
+ }
39
+
40
+ block documentation println
41
+
42
+
43
+ Math PI documentation: "An aproximation of the PI number"
44
+ Math PI documentation println
45
+
46
+ Fancy Documentation documentation println
47
+
48
+ Fancy Documentation for: Foo append: "Re-Openning Foo class to add more docs."
49
+
50
+ class Foo {
51
+ """
52
+ Fancy provides an incremental documentation feature.
53
+ """
54
+ self documentation println
55
+ }
56
+
57
+
@@ -0,0 +1,25 @@
1
+ # documentation_formatters.fy
2
+ # Example of fancy's documentation formatters
3
+
4
+ foo = Object new
5
+
6
+ Fancy Documentation for: foo is: """
7
+ ## Fancy documentation.
8
+
9
+ It should be possible to set documentation for any _arbitray object_.
10
+ Doing so will expose it on the API documents.
11
+ This can be useful for constants, or singleton objects.
12
+
13
+ ## Fancy Documentation formatters
14
+
15
+ Fancy you to create custom documentation formatters,
16
+ thus, allowing you to display an object document in a well
17
+ formatted way for different environments, eg. when using the
18
+ interactive REPL you may want *ANSI* _colored_ output, or maybe
19
+ we create a tool to generate MAN(1) pages, and fdoc tool
20
+ to generate HTML API docs.
21
+
22
+ """
23
+
24
+ Fancy Documentation for: foo . format: 'markdown . println
25
+
data/examples/echo.fy ADDED
@@ -0,0 +1,16 @@
1
+ # echo.fy
2
+ # Outputs contents of files
3
+
4
+ ARGV[1] if_do: |filename| {
5
+ try {
6
+ File open: filename modes: ['read] with: |f| {
7
+ until: { f eof? } do: {
8
+ f readln println
9
+ }
10
+ }
11
+ } catch IOError => e {
12
+ "[ERROR] " ++ (e message) println
13
+ }
14
+ } else: {
15
+ "Usage: fancy echo.fy [filename]" println
16
+ }
@@ -0,0 +1,4 @@
1
+ try {
2
+ "Empty catch" println
3
+ } catch StdError => e {
4
+ }
@@ -0,0 +1,9 @@
1
+ try {
2
+ "Hola" println
3
+ StdError new: "Hello" . raise!
4
+ "Hi" println
5
+ } catch StdError => e {
6
+ e println
7
+ } finally {
8
+ "Adios" println
9
+ }
@@ -0,0 +1,12 @@
1
+ # factorial.fy
2
+ # Example of factorial
3
+
4
+ class Fixnum {
5
+ def factorial {
6
+ 1 upto: self . product
7
+ }
8
+ }
9
+
10
+ 1 upto: 10 do_each: |i| {
11
+ i to_s ++ "! = " ++ (i factorial) println
12
+ }
@@ -0,0 +1,16 @@
1
+ # fibonacci.fy
2
+ # Example of fibonacci numbers
3
+
4
+ class Fixnum {
5
+ def fib {
6
+ match self -> {
7
+ case 0 -> 0
8
+ case 1 -> 1
9
+ case _ -> self - 1 fib + (self - 2 fib)
10
+ }
11
+ }
12
+ }
13
+
14
+ 15 times: |x| {
15
+ x fib println
16
+ }