相关疑难解决方法(0)

在Go中的函数中定义递归函数

我试图在Go中的另一个函数中定义一个递归函数,但我正在努力获得正确的语法.我正在寻找这样的东西:

func Function1(n) int {
   a := 10
   Function2 := func(m int) int {
      if m <= a {
         return a
      }
      return Function2(m-1)
   }

   return Function2(n)
}
Run Code Online (Sandbox Code Playgroud)

我想将Function2保留在Function1的范围内,因为它正在访问其范围的某些元素.

我怎么能在Go中这样做?

非常感谢

recursion function go

13
推荐指数
2
解决办法
2964
查看次数

切片如何包含自身?

我正在尝试使用"Go Go Programming Language"来学习Golang,并且我已经达到了关于切片的部分.他们在数组和切片之间进行比较,==因为可以将两个数组与两个切片不能进行比较.该文本如下:

"== operator for arrays of strings, it may be puzzling that slice
comparisons do not also work this way. There are two reasons why deep 
equivalence is problematic. First, unlike array elements, the elements
of a slice are indirect, making it possible for a slice to contain 
itself. Although there are ways to deal with such cases, none is 
simple, efficient, and most importantly, obvious."
Run Code Online (Sandbox Code Playgroud)

由于元素是间接的,因此切片可能包含自身的含义是什么意思?

arrays comparison go slice

9
推荐指数
2
解决办法
735
查看次数

标签 统计

go ×2

arrays ×1

comparison ×1

function ×1

recursion ×1

slice ×1