feat: replace new keyword with this constructor syntax and ClassName.new() calls across core library and docs
Replace all uses of the `new` reserved word with explicit `this new()` constructor definitions and `ClassName.new()` instantiation calls in builtin/core.wren. Update all documentation files (classes.markdown, fiber.markdown, fn.markdown, sequence.markdown, error-handling.markdown, expressions.markdown, fibers.markdown, functions.markdown) to reflect the new constructor syntax, removing `new` keyword examples and replacing them with `ClassName.new()` patterns and `this new()` definitions.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
IO.print(new Fn {}.arity) // expect: 0
|
||||
IO.print(new Fn {|a| a}.arity) // expect: 1
|
||||
IO.print(new Fn {|a, b| a}.arity) // expect: 2
|
||||
IO.print(new Fn {|a, b, c| a}.arity) // expect: 3
|
||||
IO.print(new Fn {|a, b, c, d| a}.arity) // expect: 4
|
||||
IO.print(Fn.new {}.arity) // expect: 0
|
||||
IO.print(Fn.new {|a| a}.arity) // expect: 1
|
||||
IO.print(Fn.new {|a, b| a}.arity) // expect: 2
|
||||
IO.print(Fn.new {|a, b, c| a}.arity) // expect: 3
|
||||
IO.print(Fn.new {|a, b, c, d| a}.arity) // expect: 4
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var f0 = new Fn { IO.print("zero") }
|
||||
var f1 = new Fn {|a| IO.print("one ", a) }
|
||||
var f2 = new Fn {|a, b| IO.print("two ", a, " ", b) }
|
||||
var f3 = new Fn {|a, b, c| IO.print("three ", a, " ", b, " ", c) }
|
||||
var f0 = Fn.new { IO.print("zero") }
|
||||
var f1 = Fn.new {|a| IO.print("one ", a) }
|
||||
var f2 = Fn.new {|a, b| IO.print("two ", a, " ", b) }
|
||||
var f3 = Fn.new {|a, b, c| IO.print("three ", a, " ", b, " ", c) }
|
||||
|
||||
f0.call("a") // expect: zero
|
||||
f0.call("a", "b") // expect: zero
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
var f2 = new Fn {|a, b| IO.print(a, b) }
|
||||
var f2 = Fn.new {|a, b| IO.print(a, b) }
|
||||
f2.call("a") // expect runtime error: Function expects more arguments.
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// Not structurally equal.
|
||||
IO.print(new Fn { 123 } == new Fn { 123 }) // expect: false
|
||||
IO.print(new Fn { 123 } != new Fn { 123 }) // expect: true
|
||||
IO.print(Fn.new { 123 } == Fn.new { 123 }) // expect: false
|
||||
IO.print(Fn.new { 123 } != Fn.new { 123 }) // expect: true
|
||||
|
||||
// Not equal to other types.
|
||||
IO.print(new Fn { 123 } == 1) // expect: false
|
||||
IO.print(new Fn { 123 } == false) // expect: false
|
||||
IO.print(new Fn { 123 } == "fn 123") // expect: false
|
||||
IO.print(new Fn { 123 } != 1) // expect: true
|
||||
IO.print(new Fn { 123 } != false) // expect: true
|
||||
IO.print(new Fn { 123 } != "fn 123") // expect: true
|
||||
IO.print(Fn.new { 123 } == 1) // expect: false
|
||||
IO.print(Fn.new { 123 } == false) // expect: false
|
||||
IO.print(Fn.new { 123 } == "fn 123") // expect: false
|
||||
IO.print(Fn.new { 123 } != 1) // expect: true
|
||||
IO.print(Fn.new { 123 } != false) // expect: true
|
||||
IO.print(Fn.new { 123 } != "fn 123") // expect: true
|
||||
|
||||
// Equal by identity.
|
||||
var f = new Fn { 123 }
|
||||
var f = Fn.new { 123 }
|
||||
IO.print(f == f) // expect: true
|
||||
IO.print(f != f) // expect: false
|
||||
|
||||
@@ -1 +1 @@
|
||||
new Fn(3) // expect runtime error: Argument must be a function.
|
||||
Fn.new(3) // expect runtime error: Argument must be a function.
|
||||
|
||||
@@ -1 +1 @@
|
||||
IO.print(new Fn {}) // expect: <fn>
|
||||
IO.print(Fn.new {}) // expect: <fn>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
IO.print(new Fn { 0 } is Fn) // expect: true
|
||||
IO.print(new Fn { 0 } is Object) // expect: true
|
||||
IO.print(new Fn { 0 } is String) // expect: false
|
||||
IO.print(new Fn { 0 }.type == Fn) // expect: true
|
||||
IO.print(Fn.new { 0 } is Fn) // expect: true
|
||||
IO.print(Fn.new { 0 } is Object) // expect: true
|
||||
IO.print(Fn.new { 0 } is String) // expect: false
|
||||
IO.print(Fn.new { 0 }.type == Fn) // expect: true
|
||||
|
||||
Reference in New Issue
Block a user