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:
@@ -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,4 +1,4 @@
|
||||
var list = new List
|
||||
var list = List.new()
|
||||
|
||||
IO.print(list.count) // expect: 0
|
||||
IO.print(list) // expect: []
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user