Make constructors just methods.

* Eliminate "new" reserved word.
* Allow "this" before a method definition to define a constructor.
* Only create a default constructor for classes that don't define one.
This commit is contained in:
Bob Nystrom
2015-07-10 09:18:22 -07:00
parent 0ddaa2517c
commit 5fb6186d7d
221 changed files with 864 additions and 654 deletions
+1 -1
View File
@@ -18,6 +18,6 @@ class Foo {
toString { "Foo.toString" }
}
IO.print([1, new Foo, 2].join(", ")) // expect: 1, Foo.toString, 2
IO.print([1, Foo.new(), 2].join(", ")) // expect: 1, Foo.toString, 2
// TODO: Handle lists that contain themselves.
+1 -1
View File
@@ -1,4 +1,4 @@
var list = new List
var list = List.new()
IO.print(list.count) // expect: 0
IO.print(list) // expect: []
+2 -2
View File
@@ -1,7 +1,7 @@
var a = [1, 4, 2, 1, 5]
var b = ["W", "o", "r", "l", "d"]
var max = new Fn {|a, b| a > b ? a : b }
var sum = new Fn {|a, b| a + b }
var max = Fn.new {|a, b| a > b ? a : b }
var sum = Fn.new {|a, b| a + b }
IO.print(a.reduce(max)) // expect: 5
IO.print(a.reduce(10, max)) // expect: 10
+1 -1
View File
@@ -12,6 +12,6 @@ class Foo {
toString { "Foo.toString" }
}
IO.print([1, new Foo, 2]) // expect: [1, Foo.toString, 2]
IO.print([1, Foo.new(), 2]) // expect: [1, Foo.toString, 2]
// TODO: Handle lists that contain themselves.