Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

HUUGE CHANGE: Semicolons are history - or at least completely optiona…

…l now! A newline will do it, except for literal strings, hashes, arrays & blocks, which _can_ have linebreaks in them. Much nicer syntax for Fancy. Yay!
  • Loading branch information...
commit 0e8107391a1a57c9d958e141e8f16b6ce1602057 1 parent f708b6c
@bakkdoor authored
Showing with 1,309 additions and 1,292 deletions.
  1. +1 −1  bin/ifancy
  2. +1 −1  examples/argv.fnc
  3. +3 −3 examples/arithmetic.fnc
  4. +10 −10 examples/armstrong_numbers.fnc
  5. +21 −21 examples/array.fnc
  6. +6 −6 examples/blocks.fnc
  7. +8 −8 examples/boolean.fnc
  8. +24 −24 examples/class.fnc
  9. +5 −5 examples/closures.fnc
  10. +1 −1  examples/factorial.fnc
  11. +1 −1  examples/fibonacci.fnc
  12. +6 −6 examples/files.fnc
  13. +31 −31 examples/game_of_life.fnc
  14. +1 −1  examples/hello_world.fnc
  15. +7 −7 examples/html_generator.fnc
  16. +6 −6 examples/metadata.fnc
  17. +6 −6 examples/methods.fnc
  18. +4 −4 examples/nested_classes.fnc
  19. +6 −6 examples/numbers.fnc
  20. +15 −15 examples/person.fnc
  21. +5 −5 examples/project-euler/02.fnc
  22. +2 −2 examples/require.fnc
  23. +7 −6 examples/scope.fnc
  24. +9 −9 lib/argv.fnc
  25. +55 −55 lib/array.fnc
  26. +6 −6 lib/block.fnc
  27. +39 −39 lib/boot.fnc
  28. +7 −7 lib/class.fnc
  29. +5 −5 lib/console.fnc
  30. +2 −2 lib/directory.fnc
  31. +52 −52 lib/enumerable.fnc
  32. +45 −45 lib/fancy_spec.fnc
  33. +9 −9 lib/file.fnc
  34. +6 −6 lib/hash.fnc
  35. +3 −3 lib/method.fnc
  36. +8 −8 lib/nil_class.fnc
  37. +10 −10 lib/number.fnc
  38. +16 −16 lib/object.fnc
  39. +27 −27 lib/rubinius/array.fnc
  40. +8 −8 lib/rubinius/console.fnc
  41. +5 −5 lib/rubinius/file.fnc
  42. +1 −1  lib/rubinius/object.fnc
  43. +3 −3 lib/rubinius/system.fnc
  44. +12 −12 lib/set.fnc
  45. +9 −9 lib/string.fnc
  46. +2 −2 lib/symbol.fnc
  47. +5 −5 lib/true_class.fnc
  48. +5 −6 lib/version.fnc
  49. +1 −1  src/parser/fancy.lex
  50. +100 −82 src/parser/fancy.y
  51. +2 −2 tests/argv.fnc
  52. +161 −161 tests/array.fnc
  53. +29 −29 tests/block.fnc
  54. +142 −143 tests/class.fnc
  55. +9 −9 tests/documentation.fnc
  56. +16 −16 tests/exception.fnc
  57. +46 −46 tests/file.fnc
  58. +44 −44 tests/hash.fnc
  59. +8 −8 tests/method.fnc
  60. +17 −17 tests/nil_class.fnc
  61. +40 −40 tests/number.fnc
  62. +73 −73 tests/object.fnc
  63. +16 −16 tests/parsing/sexp.fnc
  64. +7 −7 tests/scope.fnc
  65. +5 −5 tests/set.fnc
  66. +40 −40 tests/string.fnc
  67. +8 −8 tests/symbol.fnc
  68. +19 −19 tests/true_class.fnc
View
2  bin/ifancy
@@ -1,7 +1,7 @@
#!/usr/bin/env fancy
["Welcome to the (still very simple) Fancy REPL",
- "Fancy " ++ FANCY_VERSION] println;
+ "Fancy " ++ FANCY_VERSION] println
ARGV rest each: |file| {
"LOADING: " ++ file println;
View
2  examples/argv.fnc
@@ -1,4 +1,4 @@
-"This will always get printed, even when required from another file" println;
+"This will always get printed, even when required from another file" println
ARGV[0] == __FILE__ if_true: {
"This will get printed, if this file is directly run with fancy" println
View
6 examples/arithmetic.fnc
@@ -1,4 +1,4 @@
-23 + 32432.32 println;
-324432.432 - 32432.4324 println;
-32432 * 432.32 println;
+23 + 32432.32 println
+324432.432 - 32432.4324 println
+32432 * 432.32 println
432 / 12319 println
View
20 examples/armstrong_numbers.fnc
@@ -5,26 +5,26 @@
def class Number {
def decimals {
"""Returns all decimals of a Number as an Array.
- E.g. 123 decimals # => [1,2,3]""";
+ E.g. 123 decimals # => [1,2,3]"""
- decimals = [];
- tmp = self;
+ decimals = []
+ tmp = self
{ tmp >= 10 } while_true: {
- decimals << (tmp modulo: 10);
+ decimals << (tmp modulo: 10)
tmp = (tmp div: 10)
- };
- decimals << tmp;
+ }
+ decimals << tmp
decimals
}
def armstrong? {
- "Indicates, if a Number is a Armstrong Number.";
+ "Indicates, if a Number is a Armstrong Number."
- decimals = self decimals;
- n_decimals = decimals size;
+ decimals = self decimals
+ n_decimals = decimals size
decimals map: |x| { x ** n_decimals } . sum == self
}
-};
+}
# output alls Armstrong Numbers between 0 and 10000
0 upto: 10000 do_each: |i| {
View
42 examples/array.fnc
@@ -1,51 +1,51 @@
# some array example code
# create an array
-arr = [1,2,3,4,5,6];
+arr = [1,2,3,4,5,6]
# print each element squared
arr each: |x| {
x squared println
-};
+}
# display each element with its index in the array
arr each_with_index: |x i| {
"Index " ++ i ++ " -> " ++ x println
-};
+}
# print the array of squared elements
-arr map: 'squared . inspect println;
+arr map: 'squared . inspect println
# print the array of doubled elements
-arr map: 'doubled . inspect println;
+arr map: 'doubled . inspect println
# print array of all elements smaller than 4
-arr select: |x| { x < 4 } . inspect println;
+arr select: |x| { x < 4 } . inspect println
# print array of all elements that are not smaller than 4
-arr reject: |x| { x < 4 } . inspect println;
+arr reject: |x| { x < 4 } . inspect println
# prints: [5, 6]
-arr take_while: |x| { x < 5 } . inspect println;
+arr take_while: |x| { x < 5 } . inspect println
-"testing reduce:with: " print;
-arr reduce: |acc x| { acc * x } with: 1 . println; # same as: 1*1*2*3*4*5*6
+"testing reduce:with: " print
+arr reduce: |acc x| { acc * x } with: 1 . println # same as: 1*1*2*3*4*5*6
-"testing any?: " print;
-arr any?: |x| { x > 3 } . println; # prints: true
+"testing any?: " print
+arr any?: |x| { x > 3 } . println # prints: true
-"testing all?: " print;
-arr all?: |x| { x < 7 } . println; # prints: true
+"testing all?: " print
+arr all?: |x| { x < 7 } . println # prints: true
-"testing from:to: " print;
-arr [[3,5]] . inspect println; # prints: [4, 5, 6]
+"testing from:to: " print
+arr [[3,5]] . inspect println # prints: [4, 5, 6]
# some other handy methods
-"testing size: " print;
-arr size println; # prints: 6
+"testing size: " print
+arr size println # prints: 6
-"testing to_s: " print;
-arr to_s println; # prints: 123456
+"testing to_s: " print
+arr to_s println # prints: 123456
-"testing inspect: " print;
+"testing inspect: " print
arr inspect println # prints: [1, 2, 3, 4, 5, 6] : Array
View
12 examples/blocks.fnc
@@ -1,12 +1,12 @@
-x = { Console println: "Println from within block!" };
-x call; # calls x and prints: "Println from within block!"
+x = { Console println: "Println from within block!" }
+x call # calls x and prints: "Println from within block!"
-y = |x y| { Console println: $ x + y };
-y call: [2, 3]; # calls y and prints: 5
+y = |x y| { Console println: $ x + y }
+y call: [2, 3] # calls y and prints: 5
# prints numbers 0 to 20
-zahl = 0;
+zahl = 0
{ zahl <= 20 } while_true: {
- Console println: zahl;
+ Console println: zahl
zahl = zahl + 1
}
View
16 examples/boolean.fnc
@@ -1,20 +1,20 @@
# some boolean expressions & logicial operations
-true and: true . println; # true
-true and: nil . println; # nil
-nil and: nil . println; # nil
+true and: true . println # true
+true and: nil . println # nil
+nil and: nil . println # nil
-true or: true . println; # true
-true or: nil . println; # true
-nil or: nil . println; # nil
+true or: true . println # true
+true or: nil . println # true
+nil or: nil . println # nil
-"--------------" println;
+"--------------" println
# won't print string
nil if_true: {
"this should _not_ be displayed" println
-};
+}
# will print string
nil if_false: {
View
48 examples/class.fnc
@@ -1,64 +1,64 @@
def class Bar {
def initialize {
Console println: "In Bar constructor!"
- };
+ }
def say_hello: name {
- Console print: "Hello, ";
+ Console print: "Hello, "
Console println: name
}
-};
+}
def class Foo : Bar {
def initialize: name {
- Console println: "gonna set @name";
+ Console println: "gonna set @name"
@name = name
- };
+ }
def say_hello {
- Console print: "Hello, ";
- Console println: @name;
+ Console print: "Hello, "
+ Console println: @name
{@block call} if: @block
- };
+ }
def on_hello_do: block {
@block = block
}
-};
+}
-bar = Bar new;
-bar say_hello: "Chris";
+bar = Bar new
+bar say_hello: "Chris"
-foo = Foo new: "Chris from Constructor";
-foo say_hello;
+foo = Foo new: "Chris from Constructor"
+foo say_hello
foo on_hello_do: {
Console println: "Call me when calling on_hello! :)"
-};
-foo say_hello;
+}
+foo say_hello
-foo class println; # print the class of foo
+foo class println # print the class of foo
# define a singleton method on foo object
foo define_singleton_method: "foo!" with: {
"In foo method :D" println
-};
+}
-foo foo!;
+foo foo!
# define a 'normal' method on Foo class
# (instance method for all instances of Foo)
foo class define_method: "foo_for_all:" with: |x| {
- "In foo_for_all method (defined for all instances of Foo class)" println;
+ "In foo_for_all method (defined for all instances of Foo class)" println
"Got argument: " ++ x println
-};
+}
-foo2 = Foo new;
-foo2 foo_for_all: "hello, test! :)";
-foo foo_for_all: "hello, test (again)! :)";
+foo2 = Foo new
+foo2 foo_for_all: "hello, test! :)"
+foo foo_for_all: "hello, test (again)! :)"
# define a class method on Foo class
# it's the same as calling 'define_singleton_method:with:' on class
foo class define_class_method: "cool_class_method:" with: |arg| {
"In class method for Foo! Argument given: " ++ arg println
-};
+}
# the following is the same as:
# foo class cool_class_method: "Some argument string"
View
10 examples/closures.fnc
@@ -2,19 +2,19 @@
def create_counter: number {
closure = {
number = number + 1
- };
+ }
closure
-};
+}
# create a counter from 100 upwards
-closure = self create_counter: 100;
+closure = self create_counter: 100
# this will print numbers 100 - 120
20 times: {
Console println: $ closure call
-};
+}
# create a counter from 500 upwards
-closure = self create_counter: 500;
+closure = self create_counter: 500
# this will print numbers 500 - 510
10 times: {
Console println: $ closure call
View
2  examples/factorial.fnc
@@ -2,7 +2,7 @@ def class Number {
def factorial {
1 upto: self . product
}
-};
+}
1 upto: 10 do_each: |i| {
i to_s ++ "! = " ++ (i factorial) println
View
2  examples/fibonacci.fnc
@@ -10,7 +10,7 @@ def class Number {
}
}
}
-};
+}
15 times: |x| {
x fib println
View
12 examples/files.fnc
@@ -1,20 +1,20 @@
{
Directory create: "tmp/"
-} unless: $ Directory exists?: "tmp/";
+} unless: $ Directory exists?: "tmp/"
File open: "tmp/Hello-World.txt" modes: ['write] with: |f| {
f write: "Hello, world" . newline
-};
+}
-File delete: "tmp/Hello-World.txt";
+File delete: "tmp/Hello-World.txt"
-arr = [1,2,3,4];
+arr = [1,2,3,4]
File open: "tmp/Array-Test.txt" modes: ['write] with: |f| {
arr each: |x| {
f writeln: x
}
-};
+}
-File delete: "tmp/Array-Test.txt";
+File delete: "tmp/Array-Test.txt"
Directory delete: "tmp/"
View
62 examples/game_of_life.fnc
@@ -1,7 +1,7 @@
## Conway's Game of Life in Fancy :)
def class World {
- self read_write_slots: ['matrix];
+ self read_write_slots: ['matrix]
def World with_height: height and_width: width {
World new: [height, width]
@@ -17,36 +17,36 @@ def class World {
}
def initialize: size {
- "Initialize a World with a given size ([height, width]).";
+ "Initialize a World with a given size ([height, width])."
- self initialize;
- height = size[0];
- width = size[1];
- @last_alive = [];
- @matrix = Array new: height;
+ self initialize
+ height = size[0]
+ width = size[1]
+ @last_alive = []
+ @matrix = Array new: height
height times: |i| {
@matrix at: i put: (Array new: width with: 0)
}
}
def [] index {
- "Return the row for a given index.";
+ "Return the row for a given index."
@matrix[index]
}
def simulate: amount_generations {
- "Simulate the World for a given amount of iterations (generations).";
+ "Simulate the World for a given amount of iterations (generations)."
- self display: 0;
+ self display: 0
amount_generations times: |i| {
- System sleep: 500; # sleep 500 ms
- self simulate;
+ System sleep: 500 # sleep 500 ms
+ self simulate
self display: (i + 1)
}
}
def display {
- "Display the World (print on Screen).";
+ "Display the World (print on Screen)."
@matrix each: |row| {
row each: |entry| {
@@ -55,21 +55,21 @@ def class World {
} else: {
". " print
}
- };
+ }
"" println
}
}
def display: iteration {
- "Display the World (print on Screen) with the current iteration count.";
+ "Display the World (print on Screen) with the current iteration count."
- Console clear;
- "Generation: " ++ iteration println;
+ Console clear
+ "Generation: " ++ iteration println
self display
}
def was_alive?: pos {
- "Indicates, if a cell ([row,column]) was alive in the last generation.";
+ "Indicates, if a cell ([row,column]) was alive in the last generation."
@last_alive[pos[0]] if_do: |row| {
row[pos[1]] == 1
@@ -77,23 +77,23 @@ def class World {
}
def live: pos {
- "Sets the given cell ([row,column]) alive.;";
+ "Sets the given cell ([row,column]) alive."
(@matrix[pos[0]]) at: (pos[1]) put: 1
}
def die: pos {
- "Sets the given cell ([row,column]) dead.;";
+ "Sets the given cell ([row,column]) dead."
(@matrix[pos[0]]) at: (pos[1]) put: 0
}
def simulate {
- "Simulates the world one iteration.";
+ "Simulates the world one iteration."
- @last_alive = @matrix map: |row| { row select_with_index: |c| { c == 1 } };
+ @last_alive = @matrix map: |row| { row select_with_index: |c| { c == 1 } }
@matrix each_with_index: |row i| {
row each_with_index: |column j| {
# check amount of neighbors
- n_neighbors = self neighbors_of: [i, j];
+ n_neighbors = self neighbors_of: [i, j]
self was_alive?: [i,j] . if_true: {
n_neighbors <= 1 or: (n_neighbors >= 4) if_true: {
self die: [i,j]
@@ -110,19 +110,19 @@ def class World {
}
def neighbors_of: pos {
- row = pos[0];
- column = pos[1];
+ row = pos[0]
+ column = pos[1]
neighbors = @offsets map: |o| {
@matrix[row + (o[0])] if_do: |r| {
r[column + (o[1])]
}
- };
+ }
neighbors select: |x| { x != 0 } . size
}
-};
+}
-X = 1;
+X = 1
PULSAR = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, X, X, X, 0, 0, 0, X, X, X, 0, 0, 0],
@@ -139,9 +139,9 @@ PULSAR = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, X, X, X, 0, 0, 0, X, X, X, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- ];
+ ]
-w = World new;
-w matrix: PULSAR;
+w = World new
+w matrix: PULSAR
w simulate: 20
View
2  examples/hello_world.fnc
@@ -1,3 +1,3 @@
-Console println: "Hello, World!";
+Console println: "Hello, World!"
# another way of doing this:
"Hello, World again!" println
View
14 examples/html_generator.fnc
@@ -8,7 +8,7 @@ def class String {
# and: self from: 0 to: (self size - 2)
self[[0,-2]]
}
-};
+}
def class HTML {
def open_tag: name {
@@ -20,19 +20,19 @@ def class HTML {
}
def unknown_message: name with_params: params {
- str = self open_tag: name;
+ str = self open_tag: name
- body = params first call;
+ body = params first call
body is_a?: Array . if_true: {
body = body join
- };
+ }
str ++ body ++ (self close_tag: name)
}
-};
+}
-# lets generate some simple HTML output ;)
-h = HTML new;
+# lets generate some simple HTML output )
+h = HTML new
h html: {
h body: {
[
View
12 examples/metadata.fnc
@@ -1,12 +1,12 @@
-{ Directory create: "tmp/" } unless: $ Directory exists?: "tmp/";
+{ Directory create: "tmp/" } unless: $ Directory exists?: "tmp/"
# let's create an object with metadata attached to it
-f = File open: "tmp/metadata" modes: ['write];
+f = File open: "tmp/metadata" modes: ['write]
# set the metadata for f
-f meta: <['downloaded_from => "http://www.fancy-lang.org", 'important => true]>;
+f meta: <['downloaded_from => "http://www.fancy-lang.org", 'important => true]>
# retrieve the metadata for f and print it
-"File: '" ++ (f filename) ++ "' downloaded from: " ++ (f meta ['downloaded_from]) println;
+"File: '" ++ (f filename) ++ "' downloaded from: " ++ (f meta ['downloaded_from]) println
-f close;
-File delete: "tmp/metadata";
+f close
+File delete: "tmp/metadata"
Directory delete: "tmp/"
View
12 examples/methods.fnc
@@ -2,25 +2,25 @@ def class Foo {
def bar {
Console println: "version 1"
}
-};
+}
-f = Foo new;
-f bar; # prints: version 1
+f = Foo new
+f bar # prints: version 1
# redefine Foo#bar
def class Foo {
def bar {
Console println: "version 2"
}
-};
+}
-f bar; # prints: version 2
+f bar # prints: version 2
# redefine Foo#bar again
def class Foo {
def bar {
Console println: "version 3"
}
-};
+}
f bar # prints: version 3
View
8 examples/nested_classes.fnc
@@ -8,9 +8,9 @@ def class Outer {
def to_s {
"Outer"
}
-};
+}
-o = Outer new;
-o println;
-i = Outer::Inner new;
+o = Outer new
+o println
+i = Outer::Inner new
i println
View
12 examples/numbers.fnc
@@ -1,9 +1,9 @@
--10 abs println; # prints: 10
-10 abs println; # prints: 10
-0 abs println; # prints: 0
+-10 abs println # prints: 10
+10 abs println # prints: 10
+0 abs println # prints: 0
-"" println;
+"" println
--10 negate println; # prints: 10
-10 negate println; # prints: -10
+-10 negate println # prints: 10
+10 negate println # prints: -10
0 negate println # prints: 0
View
30 examples/person.fnc
@@ -2,26 +2,26 @@
# (C) 2010 Christopher Bertels <chris@fancy-lang.org>
def class City {
- self read_slots: ['city];
+ self read_slots: ['city]
def initialize: name {
@name = name
- };
+ }
def to_s {
"City: " ++ @name
}
-};
+}
def class Person {
# creates getters & setters for slots
- self read_write_slots: ['name, 'age, 'city];
+ self read_write_slots: ['name, 'age, 'city]
# Person class method for creating a new person with a name, age and city
def Person name: name age: age city: city {
- p = Person new;
- p name: name;
- p age: age;
- p city: city;
+ p = Person new
+ p name: name
+ p age: age
+ p city: city
p
}
@@ -42,19 +42,19 @@ def class Person {
city is_a?: City . if_true: {
@city = city
}
- };
+ }
def to_s {
"Person: " ++ @name ++ ", " ++ @age ++ " years old, living in " ++ @city
}
-};
+}
# usage example:
-osna = City new: "Osnabrück";
-p = Person name: "Christopher" age: 23 city: osna;
-p println;
+osna = City new: "Osnabrück"
+p = Person name: "Christopher" age: 23 city: osna
+p println
-berlin = City new: "Berlin";
-p go_to: berlin; # => p city will then be set to berlin
+berlin = City new: "Berlin"
+p go_to: berlin # => p city will then be set to berlin
p println
View
10 examples/project-euler/02.fnc
@@ -6,16 +6,16 @@
# Find the sum of all the even-valued terms in the sequence which do
# not exceed four million.
-fibs = [1, 2];
+fibs = [1, 2]
# insert into fibs as long as the sum of the last two numbers doesn't
# exceed 4000000
{ fibs[-1] + (fibs[-2]) <= 4000000 } while_true: {
fibs << (fibs last: 2 . sum)
-};
+}
-"fibonacci sequence:" println;
-fibs inspect println;
+"fibonacci sequence:" println
+fibs inspect println
-"sum: " print;
+"sum: " print
fibs select: 'even? . sum println
View
4 examples/require.fnc
@@ -1,6 +1,6 @@
# loads & evals arithmetic.fnc in current directory
# alternatively you can omit the ".fnc" extension
-require: "arithmetic.fnc";
+require: "arithmetic.fnc"
-"in require.fnc!" println;
+"in require.fnc!" println
ARGV println # prints any given command-line arguments as an array
View
13 examples/scope.fnc
@@ -1,12 +1,13 @@
def class ScopeTest {
def test {
- "in ScopeTest#test" println;
+ "in ScopeTest#test" println
__current_scope__ parent define: "foo" value: "bar"
}
-};
+}
-t = ScopeTest new;
-foo inspect println; # => nil
-t test;
-foo inspect println; # => "bar"
+t = ScopeTest new
+foo inspect println # => nil
+t test
+foo inspect println # => "bar"
__current_scope__ get: "foo" . inspect println # => "bar" (same as line above)
+
View
18 lib/argv.fnc
@@ -1,5 +1,5 @@
def ARGV for_option: op_name do: block {
- "Runs a given block if an option is in ARGV.";
+ "Runs a given block if an option is in ARGV."
ARGV index: op_name . if_do: |idx| {
block argcount > 0 if_true: {
@@ -10,14 +10,14 @@ def ARGV for_option: op_name do: block {
block call
}
}
-};
+}
def ARGV for_options: op_names do: block {
- "Runs a given block if any of the given options is in ARGV.";
+ "Runs a given block if any of the given options is in ARGV."
- done = nil;
- i = 0;
- size = op_names size;
+ done = nil
+ i = 0
+ size = op_names size
{ done not and: (i < size) } while_true: {
ARGV index: (op_names[i]) . if_do: |idx| {
block argcount > 0 if_true: {
@@ -26,9 +26,9 @@ def ARGV for_options: op_names do: block {
}
} else: {
block call
- };
+ }
done = true
- };
+ }
i = i + 1
}
-};
+}
View
110 lib/array.fnc
@@ -1,11 +1,11 @@
def class Array {
- "Array class. Arrays are dynamically resizable containers with a constant-time index-based access to members.";
+ "Array class. Arrays are dynamically resizable containers with a constant-time index-based access to members."
- self include: Enumerable;
+ self include: Enumerable
def NATIVE [] index {
"""Given an Array of 2 Numbers, it returns the sub-array between the given indices.
- If given a Number, returns the element at that index.""";
+ If given a Number, returns the element at that index."""
# if given an Array, interpret it as a from:to: range substring
index is_a?: Array . if_true: {
@@ -16,12 +16,12 @@ def class Array {
}
def rest {
- "Returns all elements except the first one as a new Array.";
+ "Returns all elements except the first one as a new Array."
self from: 1 to: -1
}
def === other {
- "Compares two Arrays where order does not matter.";
+ "Compares two Arrays where order does not matter."
other is_a?: Array . if_true: {
self size != (other size) if_true: {
@@ -33,22 +33,22 @@ def class Array {
}
def index: item {
- "Returns the index of an item (or nil, if it isn't in the Array).";
+ "Returns the index of an item (or nil, if it isn't in the Array)."
- found_idx = nil;
- i = 0;
- size = self size;
+ found_idx = nil
+ i = 0
+ size = self size
{ found_idx not and: (i < size) } while_true: {
item == (self at: i) if_true: {
found_idx = i
- };
+ }
i = i + 1
- };
+ }
found_idx
}
def find: item {
- "Returns the item, if it's in the Array or nil (if not found).";
+ "Returns the item, if it's in the Array or nil (if not found)."
item is_a?: Block . if_true: {
self find_by: item
@@ -60,61 +60,61 @@ def class Array {
}
def find_by: block {
- "Like find: but takes a block that gets called with each element to find it.";
+ "Like find: but takes a block that gets called with each element to find it."
- found = nil;
- i = 0;
- size = self size;
+ found = nil
+ i = 0
+ size = self size
{ found not and: (i < size) } while_true: {
- item = block call: [(self at: i)];
+ item = block call: [(self at: i)]
item nil? if_false: {
found = self at: i
- };
+ }
i = i + 1
- };
+ }
found
}
def values_at: idx_arr {
- "Returns new Array with elements at given indices.";
+ "Returns new Array with elements at given indices."
- values = [];
+ values = []
idx_arr each: |idx| {
values << (self at: idx)
- };
+ }
values
}
def >> other_arr {
- "Returns new Array with elements of other_arr appended to these.";
+ "Returns new Array with elements of other_arr appended to these."
- arr = self clone;
+ arr = self clone
arr append: other_arr
}
def join: join_str {
"""Joins all elements in the Array by a given String.
- E.g.: [1,2,3] join: ', ' # => '1,2,3'""";
+ E.g.: [1,2,3] join: ', ' # => '1,2,3'"""
- str = "";
- max_idx = self size - 1;
+ str = ""
+ max_idx = self size - 1
self each_with_index: |x i| {
- str = str ++ x;
+ str = str ++ x
i < max_idx if_true: {
str = str ++ join_str
}
- };
+ }
str
}
def join {
- "Joins all elements with the empty String.";
+ "Joins all elements with the empty String."
# TODO: this is a hack, somehow it doesn't work with a literal string
self join: ""
}
def NATIVE each_with_index: block {
- "Iterate over all elements in Array. Calls a given Block with each element and its index.";
+ "Iterate over all elements in Array. Calls a given Block with each element and its index."
self size times: |idx| {
block call: [self at: idx, idx]
@@ -122,51 +122,51 @@ def class Array {
}
def NATIVE select_with_index: condition {
- "Same as select, just gets also called with an additional argument for each element's index value.";
+ "Same as select, just gets also called with an additional argument for each element's index value."
- coll = [];
+ coll = []
self each_with_index: |x i| {
{ coll << [x, i] } if: $ condition call: [x, i]
- };
+ }
coll
- };
+ }
def NATIVE reject!: condition {
- "Removes all elements in place, that meet the condition.";
+ "Removes all elements in place, that meet the condition."
- entries = self select_with_index: |x i| { condition call: [x] };
- self remove_at: $ entries map: |e| { e second };
+ entries = self select_with_index: |x i| { condition call: [x] }
+ self remove_at: $ entries map: |e| { e second }
self
}
def select!: condition {
- "Removes all elements in place, that don't meet the condition.";
+ "Removes all elements in place, that don't meet the condition."
self reject!: |x| { condition call: [x] . not }
}
def compact! {
- "Removes all nil-value elements in place.";
+ "Removes all nil-value elements in place."
self reject!: |x| { x nil? }
}
def remove: obj {
- "Removes all occurances of obj in the Array.";
+ "Removes all occurances of obj in the Array."
self remove_at: (self indices: obj)
}
def remove_if: condition {
- "Removes all elements that meet the given condition block.";
+ "Removes all elements that meet the given condition block."
self remove_at:
- (self select_with_index: condition
- . map: 'second)
+ (self select_with_index: condition .
+ map: 'second)
}
def println {
- "Prints each element on a seperate line.";
+ "Prints each element on a seperate line."
self each: |x| {
x println
@@ -174,23 +174,23 @@ def class Array {
}
def to_s {
- "Returns String representation of Array.";
+ "Returns String representation of Array."
self reduce: |x y| { x ++ y } with: ""
}
def * num {
- "Returns a new Array that contains the elements of self num times in a row.";
+ "Returns a new Array that contains the elements of self num times in a row."
- arr = [];
+ arr = []
num times: {
arr append: self
- };
+ }
arr
}
def + other_arr {
- "Returns concatenation with another Array.";
+ "Returns concatenation with another Array."
self clone append: other_arr
}
@@ -199,17 +199,17 @@ def class Array {
"""
Similar to Array#each: but calls an additional Block between
calling the first Block for each element in self.
- """;
+ """
- count = 0;
- size = self size;
+ count = 0
+ size = self size
self each: |x| {
# NOTICE:
# use [x] instead of x since self is an array already:
- each_block call: [x];
+ each_block call: [x]
count == (size - 1) if_false: {
between_block call
- };
+ }
count = count + 1
}
}
View
12 lib/block.fnc
@@ -1,25 +1,25 @@
def class Block {
def NATIVE while_true: block {
"""Executes a given Block while self evals to true\nExample:
- i = 0;
- { i < 10 } while_true: { x println; x = x + 1 }""";
+ i = 0
+ { i < 10 } while_true: { x println x = x + 1 }"""
self call if_true: {
- block call;
+ block call
self while_true: block
}
}
def while_false: block {
"""Executes a given Block while self evals to nil\nExample:
- i = 0;
- { i >= 10 } while_false: { i println; i = i + 1 }""";
+ i = 0
+ { i >= 10 } while_false: { i println i = i + 1 }"""
{ self call not } while_true: block
}
def while_nil: block {
- "Same as Block#while_false:";
+ "Same as Block#while_false:"
self while_false: block
}
View
78 lib/boot.fnc
@@ -8,34 +8,34 @@
# current list (if adding them here is really necessary at all).
# a hack for "def NATIVE" method definitions:
-NATIVE = Object new;
+# NATIVE = Object new
-require: "object";
-require: "class";
-require: "true_class";
-require: "nil_class";
-require: "number";
-require: "enumerable";
-require: "string";
-require: "array";
-require: "block";
-require: "file";
-require: "directory";
-require: "fancy_spec";
-require: "console";
-require: "hash";
-require: "set";
-require: "symbol";
-require: "method";
+require: "object"
+require: "class"
+require: "true_class"
+require: "nil_class"
+require: "number"
+require: "enumerable"
+require: "string"
+require: "array"
+require: "block"
+require: "file"
+require: "directory"
+require: "fancy_spec"
+require: "console"
+require: "hash"
+require: "set"
+require: "symbol"
+require: "method"
# version holds fancy's version number
-require: "version";
-require: "argv";
+require: "version"
+require: "argv"
ARGV for_options: ["-v", "--version"] do: {
- "fancy " ++ FANCY_VERSION println;
+ "fancy " ++ FANCY_VERSION println
"(C) 2010 Christopher Bertels <chris@fancy-lang.org>" println
-};
+}
ARGV for_options: ["--help", "-h"] do: {
["Usage: fancy [option] [programfile] [arguments]",
@@ -48,39 +48,39 @@ ARGV for_options: ["--help", "-h"] do: {
" --sexp Print out the Fancy code within a source file as S-Expressions instead of evaluating it ",
" -c Compile given files to Ruby code and output to STDOUT or -o option, if given",
" -o Output compiled Ruby code to a given file name"] println
-};
+}
ARGV for_option: "-e" do: |eval_string| {
- eval_string eval;
+ eval_string eval
System exit # quit when running with -e
-};;
+}
-COMPILE_OUT_STREAM = Console;
+COMPILE_OUT_STREAM = Console
ARGV for_option: "-o" do: |out_file| {
- COMPILE_OUT_STREAM = File open: out_file modes: ['write];
- out_file_idx = ARGV index: "-o";
+ COMPILE_OUT_STREAM = File open: out_file modes: ['write]
+ out_file_idx = ARGV index: "-o"
# remove -o with given arg
2 times: { ARGV remove_at: out_file_idx }
-};
+}
ARGV for_option: "-c" do: {
- require: "lib/compiler/nodes.fnc";
+ require: "lib/compiler/nodes.fnc"
ARGV index: "-c" . if_do: |idx| {
ARGV[[idx + 1, -1]] each: |filename| {
- # contents = File read: filename;
- COMPILE_OUT_STREAM println: $ "#### " ++ filename ++ ": " ++ "####";
- # contents to_sexp to_ast to_ruby: COMPILE_OUT_STREAM indent: 0;
- # COMPILE_OUT_STREAM newline;
+ # contents = File read: filename
+ COMPILE_OUT_STREAM println: $ "#### " ++ filename ++ ": " ++ "####"
+ # contents to_sexp to_ast to_ruby: COMPILE_OUT_STREAM indent: 0
# COMPILE_OUT_STREAM newline
- exp = System pipe: ("bin/fancy " ++ filename ++ " --sexp");
- exp first eval to_ast to_ruby: COMPILE_OUT_STREAM indent: 0;
- COMPILE_OUT_STREAM newline;
+ # COMPILE_OUT_STREAM newline
+ exp = System pipe: ("bin/fancy " ++ filename ++ " --sexp")
+ exp first eval to_ast to_ruby: COMPILE_OUT_STREAM indent: 0
+ COMPILE_OUT_STREAM newline
COMPILE_OUT_STREAM newline
}
- };
+ }
System exit
-};
+}
# close COMPILE_OUT_STREAM if it's a File
COMPILE_OUT_STREAM != Console if_true: {
View
14 lib/class.fnc
@@ -1,6 +1,6 @@
def class Class {
def define_slot_reader: slotname {
- "Defines a slot reader method with a given name.";
+ "Defines a slot reader method with a given name."
self define_method: slotname with: {
self get_slot: slotname
@@ -8,7 +8,7 @@ def class Class {
}
def define_slot_writer: slotname {
- "Defines a slot writer method with a given name.";
+ "Defines a slot writer method with a given name."
self define_method: (slotname to_s + ":") with: |val| {
self set_slot: slotname value: val
@@ -16,7 +16,7 @@ def class Class {
}
def read_slots: slots {
- "Defines slot reader methods for all given slotnames.";
+ "Defines slot reader methods for all given slotnames."
slots each: |s| {
self define_slot_reader: s
@@ -24,7 +24,7 @@ def class Class {
}
def write_slots: slots {
- "Defines slot writer methods for all given slotnames.";
+ "Defines slot writer methods for all given slotnames."
slots each: |s| {
self define_slot_writer: s
@@ -32,16 +32,16 @@ def class Class {
}
def read_write_slots: slots {
- "Defines slot reader & writer methods for all given slotnames.";
+ "Defines slot reader & writer methods for all given slotnames."
slots each: |s| {
- self define_slot_reader: s;
+ self define_slot_reader: s
self define_slot_writer: s
}
}
def subclass?: class_obj {
- "Indicates, if a Class is a subclass of another Class.";
+ "Indicates, if a Class is a subclass of another Class."
self == class_obj if_true: {
true
View
10 lib/console.fnc
@@ -1,22 +1,22 @@
def class Console {
- "Console class. Used for stdio.";
+ "Console class. Used for stdio."
def self newline {
- "Prints a newline to stdout.";
+ "Prints a newline to stdout."
Console println: ""
}
def self println: obj {
- "Prints a given object on STDOUT, followed by a newline.";
+ "Prints a given object on STDOUT, followed by a newline."
Console print: (obj to_s ++ "\n")
}
def self readln: message {
- "Prints a given message to stdout, followed by reading a line from stdin.";
+ "Prints a given message to stdout, followed by reading a line from stdin."
- Console print: message;
+ Console print: message
Console readln
}
}
View
4 lib/directory.fnc
@@ -1,11 +1,11 @@
def class Directory {
def self exists?: dirname {
- "Indicates, if a Directory exists with a given pathname.";
+ "Indicates, if a Directory exists with a given pathname."
(File exists?: dirname) and: (File directory?: dirname)
}
def self delete: dirname {
- "Deletes a directory with a given name, if it's empty.";
+ "Deletes a directory with a given name, if it's empty."
File directory?: dirname . if_true: {
File delete: dirname
} else: {
View
104 lib/enumerable.fnc
@@ -1,99 +1,99 @@
def class Enumerable {
- "Mixin-Class with useful methods for collections that implement an 'each:' method.";
+ "Mixin-Class with useful methods for collections that implement an 'each:' method."
def include?: item {
- "Indicates, if a collection includes a given element.";
+ "Indicates, if a collection includes a given element."
self any?: |x| { item == x }
}
def any?: condition {
- "Indicates, if any element meets the condition.";
+ "Indicates, if any element meets the condition."
- found = nil;
+ found = nil
self each: |x| {
condition call: [x] . if_true: {
found = true
}
- };
+ }
found
}
def all?: condition {
- "Indicates, if all elements meet the condition.";
+ "Indicates, if all elements meet the condition."
- all = true;
+ all = true
self each: |x| {
condition call: [x] . if_false: {
all = nil
}
- };
+ }
all
}
def find: item {
- "Returns nil, if the given object isn't found, or the object, if it is found.";
+ "Returns nil, if the given object isn't found, or the object, if it is found."
item is_a?: Block . if_true: {
self find_by: item
} else: {
- found = nil;
+ found = nil
self each: |x| {
item == x if_true: {
found = x
}
- };
+ }
found
}
}
def find_by: block {
- "Similar to 'find:' but takes a block that is called for each element to find it.";
+ "Similar to 'find:' but takes a block that is called for each element to find it."
- found = nil;
+ found = nil
self each: |x| {
block call: [x] . if_do: |item| {
found = item
}
- };
+ }
found
}
def map: block {
- "Returns a new Array with the results of calling a given block for every element";
+ "Returns a new Array with the results of calling a given block for every element"
- coll = [];
+ coll = []
self each: |x| {
coll << (block call: [x])
- };
+ }
coll
}
def select: condition {
- "Returns a new Array with all elements that meet the given condition block.";
+ "Returns a new Array with all elements that meet the given condition block."
- coll = [];
+ coll = []
self each: |x| {
{ coll << x } if: $ condition call: [x]
- };
+ }
coll
}
def reject: condition {
- "Returns a new Array with all elements that don't meet the given condition block.";
+ "Returns a new Array with all elements that don't meet the given condition block."
- coll = [];
+ coll = []
self each: |x| {
{ coll << x } unless: $ condition call: [x]
- };
+ }
coll
}
def take_while: condition {
- "Returns a new Array by taking elements from the beginning as long as they meet the given condition block.";
+ "Returns a new Array by taking elements from the beginning as long as they meet the given condition block."
- coll = [];
- stop = nil;
+ coll = []
+ stop = nil
self each: |x| {
stop if_false: {
condition call: [x] . if_true: {
@@ -102,61 +102,61 @@ def class Enumerable {
stop = true
}
}
- };
+ }
coll
}
def drop_while: condition {
- "Returns a new Array by skipping elements from the beginning as long as they meet the given condition block.";
+ "Returns a new Array by skipping elements from the beginning as long as they meet the given condition block."
- coll = [];
- drop = nil;
- first_check = true;
+ coll = []
+ drop = nil
+ first_check = true
self each: |x| {
drop or: first_check . if_true: {
- drop = condition call: [x];
+ drop = condition call: [x]
first_check = nil
} else: {
coll << x
}
- };
+ }
coll
}
def reduce: block with: init_val {
- "Calculates a value based on a given block to be called on an accumulator value and an initial value.";
+ "Calculates a value based on a given block to be called on an accumulator value and an initial value."
- acc = init_val;
+ acc = init_val
self each: |x| {
acc = (block call: [acc, x])
- };
+ }
acc
}
def uniq {
- "Returns a new Array with all unique values (double entries are skipped).";
+ "Returns a new Array with all unique values (double entries are skipped)."
- uniq_vals = [];
+ uniq_vals = []
self each: |x| {
uniq_vals include?: x . if_false: {
uniq_vals << x
}
- };
+ }
uniq_vals
}
def size {
- "Returns the size of an Enumerable.";
+ "Returns the size of an Enumerable."
- i = 0;
+ i = 0
self each: |x| {
i = i + 1
- };
+ }
i
}
def empty? {
- "Indicates, if the Enumerable is empty (has no elements).";
+ "Indicates, if the Enumerable is empty (has no elements)."
self size == 0
}
@@ -165,40 +165,40 @@ def class Enumerable {
}
def last {
- "Returns the last element in an Enumerable.";
+ "Returns the last element in an Enumerable."
- item = nil;
+ item = nil
self each: |x| {
item = x
- };
+ }
item
}
def compact {
- "Returns a new Array with all values removed that are nil (return true on nil?).";
+ "Returns a new Array with all values removed that are nil (return true on nil?)."
self reject: |x| { x nil? }
}
def superior_by: comparison_block {
- "Returns the superiour element in the Enumerable that has met the given comparison block with all other elements.";
+ "Returns the superiour element in the Enumerable that has met the given comparison block with all other elements."
- retval = self first;
+ retval = self first
self each: |x| {
comparison_block call: [x, retval] . if_true: {
retval = x
}
- };
+ }
retval
}
def max {
- "Returns the maximum value in the Enumerable (via the '>' comparison message).";
+ "Returns the maximum value in the Enumerable (via the '>' comparison message)."
self superior_by: '>
}
def min {
- "Returns the minimum value in the Enumerable (via the '<' comparison message).";
+ "Returns the minimum value in the Enumerable (via the '<' comparison message)."
self superior_by: '<
}
}
View
90 lib/fancy_spec.fnc
@@ -1,7 +1,7 @@
def class FancySpec {
def initialize: description {
- @description = description;
- @test_obj = test_obj;
+ @description = description
+ @test_obj = test_obj
@spec_tests = []
}
@@ -10,53 +10,53 @@ def class FancySpec {
}
def FancySpec describe: test_obj with: block {
- it = FancySpec new: test_obj;
- block call: [it];
+ it = FancySpec new: test_obj
+ block call: [it]
it run
}
def FancySpec describe: description for: test_obj with: block {
- it = FancySpec new: description;
- it test_obj: test_obj;
- block call: [it];
+ it = FancySpec new: description
+ it test_obj: test_obj
+ block call: [it]
it run
}
def should: spec_info_string when: spec_block {
- test = SpecTest new: spec_info_string;
- test block: spec_block;
+ test = SpecTest new: spec_info_string
+ test block: spec_block
@spec_tests << test
}
def should: spec_info_string for: method_name when: spec_block {
- test = SpecTest new: spec_info_string;
- test block: spec_block;
+ test = SpecTest new: spec_info_string
+ test block: spec_block
try {
@test_obj method: method_name . if_do: |method| {
method tests << test
}
} catch MethodNotFoundError => e {
# ignore errors
- };
+ }
@spec_tests << test
}
def run {
- "Running tests for: " ++ @description ++ ": " print;
+ "Running tests for: " ++ @description ++ ": " print
@spec_tests each: |test| {
test run: @test_obj
- };
-# Console newline; Console newline;
+ }
+# Console newline Console newline
# untested_methods = @test_obj methods select: |m| {
# m tests size == 0
- # };
+ # }
# untested_methods empty? if_false: {
# ["WARNING: These methods need tests:",
# untested_methods map: 'name . select: |m| { m whitespace? not } . join: ", "] println
- # };
+ # }
Console newline
}
-};
+}
def class SpecTest {
def SpecTest failed_test: actual_and_expected {
@@ -68,8 +68,8 @@ def class SpecTest {
}
def initialize: info_str {
- { @@failed_positive = [] } unless: @@failed_positive;
- { @@failed_negative = [] } unless: @@failed_negative;
+ { @@failed_positive = [] } unless: @@failed_positive
+ { @@failed_negative = [] } unless: @@failed_negative
@info_str = info_str
}
@@ -78,54 +78,54 @@ def class SpecTest {
}
def run: test_obj {
- @@failed_positive = [];
- @@failed_negative = [];
+ @@failed_positive = []
+ @@failed_negative = []
try {
@block call
} catch IOError => e {
SpecTest failed_test: [e, "UNKNOWN"]
- };
+ }
- any_failure = nil;
+ any_failure = nil
@@failed_positive size > 0 if_true: {
- any_failure = true;
- Console newline;
- "> FAILED: " ++ test_obj ++ " should " ++ @info_str print;
+ any_failure = true
+ Console newline
+ "> FAILED: " ++ test_obj ++ " should " ++ @info_str print
self print_failed_positive
- };
+ }
@@failed_negative size > 0 if_true: {
- any_failure = true;
- Console newline;
- "> FAILED: " ++ test_obj ++ " should " ++ @info_str print;
+ any_failure = true
+ Console newline
+ "> FAILED: " ++ test_obj ++ " should " ++ @info_str print
self print_failed_negative
- };
+ }
{ "." print } unless: any_failure
}
def print_failed_positive {
- " [" ++ (@@failed_positive size) ++ " unexpected values]" println;
- "Got: " println;
+ " [" ++ (@@failed_positive size) ++ " unexpected values]" println
+ "Got: " println
@@failed_positive each: |f| {
" " ++ (f first inspect) ++ " instead of: " ++ (f second inspect) println
}
}
def print_failed_negative {
- " [" ++ (@@failed_negative size) ++ " unexpected values]" println;
- "Should not have gotten the following values: " println;
+ " [" ++ (@@failed_negative size) ++ " unexpected values]" println
+ "Should not have gotten the following values: " println
@@failed_negative each: |f| {
" " ++ (f inspect) println
}
}
-};
+}
def class PositiveMatcher {
"""PositiveMatcher expects its actual value to be equal to an
expected value.
- If the values are not equal, a SpecTest failure is generated.""";
+ If the values are not equal, a SpecTest failure is generated."""
def initialize: actual_value {
@actual_value = actual_value
@@ -145,7 +145,7 @@ def class PositiveMatcher {
def unknown_message: msg with_params: params {
"""Forwardy any other message and parameters to the object itself
- and checks the return value.""";
+ and checks the return value."""
@actual_value send: msg params: params . if_false: {
SpecTest failed_test: [@actual_value, params first]
@@ -157,12 +157,12 @@ def class PositiveMatcher {
SpecTest failed_test: [@actual_value, nil]
}
}
-};
+}
def class NegativeMatcher {
"""NegativeMatcher expects its actual value to be unequal to an
expected value.
- If the values are equal, a SpecTest failure is generated.""";
+ If the values are equal, a SpecTest failure is generated."""
def initialize: actual_value {
@actual_value = actual_value
@@ -182,7 +182,7 @@ def class NegativeMatcher {
def unknown_message: msg with_params: params {
"""Forwardy any other message and parameters to the object itself
- and checks the return value.""";
+ and checks the return value."""
@actual_value send: msg params: params . if_true: {
SpecTest failed_negative_test: @actual_value
@@ -194,16 +194,16 @@ def class NegativeMatcher {
SpecTest failed_negative_test: @actual_value
}
}
-};
+}
def class Object {
def should {
- "Returns a PositiveMatcher for self.";
+ "Returns a PositiveMatcher for self."
PositiveMatcher new: self
}
def should_not {
- "Returns a NegativeMatcher for self.";
+ "Returns a NegativeMatcher for self."
NegativeMatcher new: self
}
}
View
18 lib/file.fnc
@@ -1,9 +1,9 @@
def class File {
def self exists?: filename {
- "Indicates, if a File exists with a given filename.";
+ "Indicates, if a File exists with a given filename."
try {
- f = File open: filename modes: ['read];
- f close;
+ f = File open: filename modes: ['read]
+ f close
true
} catch IOError => e {
nil
@@ -11,29 +11,29 @@ def class File {
}
def self read: filename {
- lines = [];
+ lines = []
File open: filename modes: ['read] with: |f| {
{ f eof? } while_false: {
lines << (f readln)
}
- };
+ }
lines join: "\n"
}
def writeln: x {
- "Writes a given argument as a String followed by a newline into the File.";
+ "Writes a given argument as a String followed by a newline into the File."
- self write: x;
+ self write: x
self newline
}
def print: x {
- "Same as File#write:.";
+ "Same as File#write:."
self write: x
}
def println: x {
- "Same as File#writeln:.";
+ "Same as File#writeln:."
self writeln: x
}
}
View
12 lib/hash.fnc
@@ -1,16 +1,16 @@
def class Hash {
- "Class for Hashes (HashMaps / Dictionaries). Maps a key to a value.";
+ "Class for Hashes (HashMaps / Dictionaries). Maps a key to a value."
- self include: Enumerable;
+ self include: Enumerable
def [] key {
- "Returns the value for a given key.";
+ "Returns the value for a given key."
self at: key
}
def each: block {
- "Calls a given Block with each key and value.";
+ "Calls a given Block with each key and value."
block argcount == 1 if_true: {
self keys each: |key| {
@@ -24,7 +24,7 @@ def class Hash {
}
def each_key: block {
- "Calls a given Block with each key.";
+ "Calls a given Block with each key."
self keys each: |key| {
block call: [key]
@@ -32,7 +32,7 @@ def class Hash {
}
def each_value: block {
- "Calls a given Block with each value.";
+ "Calls a given Block with each value."
self values each: |val| {
block call: [val]
View
6 lib/method.fnc
@@ -1,12 +1,12 @@
def class Method {
def tests {
- @tests if_nil: { @tests = [] };
+ @tests if_nil: { @tests = [] }
@tests
}
def test: test_block {
- it = FancySpec new: self;
- test_block call: [it];
+ it = FancySpec new: self
+ test_block call: [it]
self tests << it
}
}
View
16 lib/nil_class.fnc
@@ -1,5 +1,5 @@
def class NilClass {
- "NilClass. The class of the singleton nil value.";
+ "NilClass. The class of the singleton nil value."
def NilClass new {
# always return nil singleton object when trying to create a new
@@ -8,37 +8,37 @@ def class NilClass {
}
def if_true: then_block else: else_block {
- "Calls else_block.";
+ "Calls else_block."
else_block call
}
def if_true: block {
- "Returns nil.";
+ "Returns nil."
nil
}
def if_false: block {
- "Calls the block.";
+ "Calls the block."
block call
}
def if_nil: block {
- "Calls the block.";
+ "Calls the block."
block call
}
def nil? {
- "Returns true.";
+ "Returns true."
true
}
def false? {
- "Returns true.";
+ "Returns true."
true
}
def true? {
- "Returns nil.";
+ "Returns nil."
nil
}
View
20 lib/number.fnc
@@ -1,20 +1,20 @@
def class Number {
- "Number class for all number values (integer & doubles for now).";
+ "Number class for all number values (integer & doubles for now)."
def squared {
- "Returns the square of a Number.";
+ "Returns the square of a Number."
self * self
}
def doubled {
- "Returns the double value of a Number.";
+ "Returns the double value of a Number."
self + self
}
def abs {
- "Returns the absolute (positive) value of a Number.";
+ "Returns the absolute (positive) value of a Number."
self < 0 if_true: {
self * -1
@@ -24,19 +24,19 @@ def class Number {
}
def negate {
- "Negates a Number (-1 becomes 1 and vice versa).";
+ "Negates a Number (-1 becomes 1 and vice versa)."
self * -1
}
def even? {
- "Indicates, if a Number is even.";
+ "Indicates, if a Number is even."
self modulo: 2 . == 0
}
def odd? {
- "Indicates, if a Number is odd.";
+ "Indicates, if a Number is odd."
self even? not
}
@@ -44,19 +44,19 @@ def class Number {
def to_num {
self
}
-};
+}
def class Enumerable {
def sum {
"""Calculates the sum of all the elements in the Enumerable
- (assuming them to be Numbers (implementing '+' & '*')).""";
+ (assuming them to be Numbers (implementing '+' & '*'))."""
self reduce: |x y| { x + y } with: 0
}
def product {
"""Calculates the product of all the elements in the Enumerable
- (assuming them to be Numbers (implementing '+' & '*')).""";
+ (assuming them to be Numbers (implementing '+' & '*'))."""
self reduce: |x y| { x * y } with: 1
}
View
32 lib/object.fnc
@@ -1,55 +1,55 @@
def class Object {
- "Root class of Fancy's class hierarchy. All classes inherit from Object.";
+ "Root class of Fancy's class hierarchy. All classes inherit from Object."
def loop: block {
- "Infinitely calls the block (loops).";
+ "Infinitely calls the block (loops)."
{ true } while_true: {
block call
}
}
def println {
- "Same as Console println: self. Prints the object on STDOUT, followed by a newline.";
+ "Same as Console println: self. Prints the object on STDOUT, followed by a newline."
Console println: self
}
def print {
- "Same as Console print: self. Prints the object on STDOUT.";
+ "Same as Console print: self. Prints the object on STDOUT."
Console print: self
}
def != other {
- "Indicates, if two objects are unequal.";
+ "Indicates, if two objects are unequal."
self == other not
}
def if_false: block {
- "Calls the block.";
+ "Calls the block."
nil
}
def if_nil: block {
- "Returns nil.";
+ "Returns nil."
nil
}
def nil? {
- "Returns nil.";
+ "Returns nil."
nil
}
def false? {
- "Returns nil.";
+ "Returns nil."
nil
}
def true? {
- "Returns nil.";
+ "Returns nil."
nil
}
def if_do: block {
- "If the object is non-nil, it calls the given block with itself as argument.";
+ "If the object is non-nil, it calls the given block with itself as argument."
self nil? if_true: {
nil
@@ -60,7 +60,7 @@ def class Object {
def if_do: then_block else: else_block {
"""If the object is non-nil, it calls the given then_block with itself as argument.
- Otherwise it calls the given else_block.""";
+ Otherwise it calls the given else_block."""
self nil? if_true: {
else_block call
@@ -70,7 +70,7 @@ def class Object {
}
def or_take: other {
- "Returns self if it's non-nil, otherwise returns the given object.";
+ "Returns self if it's non-nil, otherwise returns the given object."
self nil? if_true: {
other
@@ -88,18 +88,18 @@ def class Object {
}
def NATIVE is_a?: class_obj {
- "Indicates, if an object is an instance of a given Class.";
+ "Indicates, if an object is an instance of a given Class."
self class subclass?: class_obj
}
def || other {
- "Same as Object#or:";
+ "Same as Object#or:"
self or: other
}
def && other {
- "Same as Object#and:";
+ "Same as Object#and:"
self and: other
}
}
View
54 lib/rubinius/array.fnc
<
@@ -1,33 +1,33 @@
def class Array {
def Array new: size with: default {
- "Create a new Array with a given size and default-value.";
+ "Create a new Array with a given size and default-value."
Array new: ~[size, default] # direct call to Array.new(size, default) in ruby
- };
+ }
# methods already existing on Array in ruby
# TODO: Perhaps write better descriptions.
- self method: "each" . docstring=: "See ruby Array#each";
- self method: "==" . docstring=: "See ruby Array#==";
- self method: "clear" . docstring=: "See ruby Array#clear";
- self method: "size" . docstring=: "See ruby Array#size";
- self method: "at" . docstring=: "See ruby Array#at";
- self method: "indices" . docstring=: "See ruby Array#indices";
- self method: "first" . docstring=: "See ruby Array#first";
- self method: "reject!" . docstring=: "See ruby Array#reject!";
- self method: "select" . docstring=: "See ruby Array#select";
- self method: "<<" . docstring=: "See ruby Array#<<";
- self method: "last" . docstring=: "See ruby Array#last";
+ self method: "each" . docstring=: "See ruby Array#each"
+ self method: "==" . docstring=: "See ruby Array#=="
+ self method: "clear" . docstring=: "See ruby Array#clear"
+ self method: "size" . docstring=: "See ruby Array#size"
+ self method: "at" . docstring=: "See ruby Array#at"
+ self method: "indices" . docstring=: "See ruby Array#indices"
+ self method: "first" . docstring=: "See ruby Array#first"
+ self method: "reject!" . docstring=: "See ruby Array#reject!"
+ self method: "select" . docstring=: "See ruby Array#select"
+ self method: "<<" . docstring=: "See ruby Array#<<"
+ self method: "last" . docstring=: "See ruby Array#last"
def append: arr {
- "Appends another Array onto this one.";
+ "Appends another Array onto this one."
# TODO: should this method return a copy, or append to self and return self ?
arr is_a? Array . if_true: {
arr each: |other| {
self << other
- };
+ }
tmp # TODO: does the method return this ?
} else: {
nil
@@ -36,17 +36,17 @@ def class Array {
def clone {
"Clones (shallow copy) the Array."
- new = [];
+ new = []
self each: |x| {
new << x
- };
+ }
new
}
def remove_at: obj {
"""Removes an element at a given index.
If given an Array of indices, removes all the elements with these indices.
- Returns the deleted object if an index was given, the last deleted object for an Array given.""";
+ Returns the deleted object if an index was given, the last deleted object for an Array given."""
obj is_a?: Number . if_true: {
self delete_at: obj # call to ruby-Array#delete_at
@@ -61,30 +61,30 @@ def class Array {
def second {
- "Returns the second element in the Array";
+ "Returns the second element in the Array"
self at: 1
}
def third {
- "Returns the third element in the Array";
+ "Returns the third element in the Array"
self at: 2
}
def fourth {
- "Returns the fourth element in the Array";
+ "Returns the fourth element in the Array"
self at: 3