i'm still trying to learn golang when i chance upon the code below. i'm 
aware of function return types like int or float, and such but not a 
function. how does one interpret the return value of below code?




















*package mainimport "fmt"// fibonacci is a function that returns// a 
function that returns an int.func fibonacci(x int) func() int {  if x <= 1 
{    return x  } else {    return fibonacci(x-1) + fibonacci(x-2)  }  
return 0}func main() {  f := fibonacci()  for i := 0; i < 10; i++ {    
fmt.Println(f())  }}*


when run, it shows below errors:






*./prog.go:9:10: cannot use x (variable of type int) as type func() int in 
return statement./prog.go:11:10: invalid operation: operator + not defined 
on fibonacci(x - 1) (value of type func() int)./prog.go:13:9: cannot use 0 
(untyped int constant) as func() int value in return 
statement./prog.go:17:7: not enough arguments in call to fibonacci    have 
()    want (int)*

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/15db2a52-63f8-4b69-9c07-0488566c22f5n%40googlegroups.com.

Reply via email to