diff --git a/benchmark/fib.lua b/benchmark/fib.lua new file mode 100644 index 00000000..576024a7 --- /dev/null +++ b/benchmark/fib.lua @@ -0,0 +1,6 @@ +function fib(n) + if n < 2 then return n end + return fib(n - 2) + fib(n - 1) +end + +io.write(fib(35) .. "\n") diff --git a/benchmark/fib.py b/benchmark/fib.py new file mode 100644 index 00000000..1ce57cc5 --- /dev/null +++ b/benchmark/fib.py @@ -0,0 +1,5 @@ +def fib(n): + if n < 2: return n + return fib(n - 1) + fib(n - 2) + +print fib(35) diff --git a/benchmark/fib.wren b/benchmark/fib.wren new file mode 100644 index 00000000..76973e56 --- /dev/null +++ b/benchmark/fib.wren @@ -0,0 +1,9 @@ +var fib = fn(n) { + if (n < 2) { + n + } else { + fib.call(n - 1) + fib.call(n - 2) + } +} + +io.write(fib.call(35)) diff --git a/doc/implicit fields.txt b/doc/implicit fields.txt new file mode 100644 index 00000000..bf394eb6 --- /dev/null +++ b/doc/implicit fields.txt @@ -0,0 +1,29 @@ +Q: Can fields be implicitly declared? + +The idea is that just using a name starting with "_" somewhere in a class +automatically defines a field with that name. Implicit fields are particularly +nice because it means they don't have to be defined all before methods. (Since +we have a single-pass compiler, we would have to otherwise a method could +only refer to previously defined fields.) + +One potential problem is with nested classes. This is more important if we +consider a module effectively a class. Consider: + + class Outer { + foo { + _blah = "value" + } + + class Inner { + io.write(_blah) // Does this declare field in Inner, or access Outer? + } + } + +Looking at this, though, I think there's already a question how referring to an +outer field would work. Having an instance of Inner doesn't imply you also have +an instance of Outer. We definitely don't want to recapitulate inner classes +in Java. + +Q: What about static fields? + +A: Different naming convention? __foo?