Allow empty argument list methods.

- Compile them as calls and definitions.
- Use them for call(), clear(), run(), try(), and yield().
- Update the docs.
This commit is contained in:
Bob Nystrom
2015-02-26 23:08:36 -08:00
parent 1aaa8cff52
commit 96ceaa528b
94 changed files with 291 additions and 224 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
var f = new Fn {}
IO.print(f.call) // expect: null
IO.print(f.call()) // expect: null
+1 -1
View File
@@ -1,4 +1,4 @@
var f = new Fn {
// Hi.
}
IO.print(f.call) // expect: null
IO.print(f.call()) // expect: null
@@ -1,5 +1,5 @@
new Fn { IO.print("ok") // expect error
}.call // expect error
}.call() // expect error
// The second error is cascaded here. If it starts failing, just remove that
// expectation.
+1
View File
@@ -0,0 +1 @@
new Fn {|| null } // expect error
+1 -1
View File
@@ -1,5 +1,5 @@
var f0 = new Fn { 0 }
IO.print(f0.call) // expect: 0
IO.print(f0.call()) // expect: 0
var f1 = new Fn {|a| a }
IO.print(f1.call(1)) // expect: 1
+4 -4
View File
@@ -1,16 +1,16 @@
// Single expression body.
new Fn { IO.print("ok") }.call // expect: ok
new Fn { IO.print("ok") }.call() // expect: ok
// Curly body.
new Fn {
IO.print("ok") // expect: ok
}.call
}.call()
// Multiple statements.
new Fn {
IO.print("1") // expect: 1
IO.print("2") // expect: 2
}.call
}.call()
// Extra newlines.
new Fn {
@@ -22,4 +22,4 @@ new Fn {
IO.print("2") // expect: 2
}.call
}.call()