forked from Mirror/wren
Add trivial fib benchmark.
This commit is contained in:
6
benchmark/fib.lua
Normal file
6
benchmark/fib.lua
Normal file
@ -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")
|
||||
5
benchmark/fib.py
Normal file
5
benchmark/fib.py
Normal file
@ -0,0 +1,5 @@
|
||||
def fib(n):
|
||||
if n < 2: return n
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
|
||||
print fib(35)
|
||||
9
benchmark/fib.wren
Normal file
9
benchmark/fib.wren
Normal file
@ -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))
|
||||
29
doc/implicit fields.txt
Normal file
29
doc/implicit fields.txt
Normal file
@ -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?
|
||||
Reference in New Issue
Block a user