Hi,
The syntax is a little funky due to the fact that there is no expression separator, so the newline is significant. Therefore the "else" should be on the same line as the }
In addition your Fibonacci code use wrong variable n instead of num in the recursion call.
Cheers,
Michel
--
You received this message because you are subscribed to the Google Groups "Wren" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wren-lang+...@googlegroups.com.
To post to this group, send email to wren...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wren-lang/22f224b0-cbfe-4e4c-a6dc-94b5dbff1987%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I'm on a train right now, and will not have access to a computer for the next 5 days. In the test/benchmark there should be a Fibonacci implementation. Afaik it should use a class to perform the invocation. This looks odd, but Fn is not a first citizen in the language, since it is more object oriented then imperative. Therefore it is mostly here as a short hand with the extra arguments elimination for the class:
class MyFunc {
call(myargs...) {...}
}
In addition the var is only defined when the assignation is performed. This is the real reason behind the error.
To view this discussion on the web visit https://groups.google.com/d/msgid/wren-lang/886c517d-135b-472c-8d62-0f6bf2b8e117%40googlegroups.com.
var fib_recursionfib_recursion = new Fn {|num|if (num == 1 || num == 0) {return 1} else {return fib_recursion.call(num - 1) + fib_recursion.call(num - 2)}}IO.print(fib_recursion.call(4))
var a = a // Error: a isn't in scope yet here.
var a = new Fn { a }
var aa = new Fn { a }
if (condition) {...} // <--else ...
class Recursive {static fib(num) {if (num == 1 || num == 0) {return 1} else {return fib(num - 1) + fib(num - 2)}}}IO.print(Recursive.fib(4))
class Recursive {static fib(num) { num <= 1 ? 1 : fib(num - 1) + fib(num - 2) }}
c) Whats the best way to contribute to Wren? Can I start hacking on the TODOs in the code like the documentation states?
To view this discussion on the web visit https://groups.google.com/d/msgid/wren-lang/CAAZ5spBKq2T2W1L5m%2B0BsFVTing0j38MHSwVMe1zn%3DkneK%3D4Ug%40mail.gmail.com.