Linked by kragil on Wed 23rd Jan 2013 20:26 UTC
Permalink for comment 550242
To read all comments associated with this story, please click here.
To read all comments associated with this story, please click here.
Features
Linked by Thom Holwerda on 06/13/13 14:35 UTC
Linked by Thom Holwerda on 06/11/13 17:07 UTC
Linked by Thom Holwerda on 06/10/13 23:13 UTC
Linked by Thom Holwerda on 06/08/13 14:57 UTC
Linked by Thom Holwerda on 06/07/13 11:40 UTC
Linked by Thom Holwerda on 06/04/13 12:45 UTC
Linked by nfeske on 05/31/13 10:12 UTC
Linked by Thom Holwerda on 05/29/13 16:59 UTC
Linked by Thom Holwerda on 05/24/13 17:26 UTC
Linked by Thom Holwerda on 05/21/13 21:38 UTC
More Features »
Sponsored Links



Member since:
2010-03-11
That definition doesn't do what your Go example does. That example also requires a parameter which the Go example does not.
A similar Go function would be:
func fib(i int) int {
if i <= 1 {
return i
} else {
return fib(i-2) + fib(i-1)
}
}
That said, IMHO, the most readable Fibonacci function is Haskell's:
fib 0 = 0
fib 1 = 1
fib n = fib (n-2) + fib (n-1)
Though an encoding similar to what you provided is also possible:
fib n = if i <= 1 then i else fib (n-2) + fib (n-1)
Not as terse, but that's simply the lack of ?:, but a simple replacement would make Haskell more terse than your Vala example:
fib n = (n <= 1) ? i : fib (n-2) + fib (n-1)