Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables F#明确定义的可变变量错误它不是可变变量_Variables_F#_Mutable - Fatal编程技术网

Variables F#明确定义的可变变量错误它不是可变变量

Variables F#明确定义的可变变量错误它不是可变变量,variables,f#,mutable,Variables,F#,Mutable,我的代码中有几个可变变量。除了一个,所有的都能用 变量d获取以下几个错误 learn.fsx(33,25): error FS0027: This value is not mutable. Consider using the mutable keyword, e.g. 'let mutable d = expression' 问题是,当您查看我的代码时,该变量显然被定义为可变变量 我认为这是必要的,因为我能想到的唯一应该引起问题的东西是,变量定义之后的东西使它再次不可变 let seq =

我的代码中有几个可变变量。除了一个,所有的都能用
变量
d
获取以下几个错误

learn.fsx(33,25): error FS0027: This value is not mutable. Consider using the mutable keyword, e.g. 'let mutable d = expression'
问题是,当您查看我的代码时,该变量显然被定义为可变变量

我认为这是必要的,因为我能想到的唯一应该引起问题的东西是,变量定义之后的东西使它再次不可变

let seq = [2;2;3;3;5;6]
let exp = [[];[]]
let mutable points = 0
let mutable e = 1
let mutable state = ""
let mutable d = 1
let rec guess (x:int) =
   match points with
   |100 -> "learned"
   |_ -> match seq.[x] with
         |d -> match (exp.[((List.length exp)-2)]) with
               |[] -> if state = "right" then
                        exp.[((List.length exp)-1)]@[d]
                      else
                        state <- "right"
                        exp@[[d]]
                      points <- points + 1
                      if d = 6 then
                         d <- 1
                      else
                         d <- d + 1
                      if x = 5 then
                        (guess 0)
                      else
                        (guess (x+1))
               |_ ->  if state = "right" then
                        exp.[((List.length exp)-1)]@[d]
                      else
                        state <- "right"
                        exp@[[d]]
                      if (List.length exp.[((List.length exp)-2)]) >= 2 then
                        d <- (exp.[((List.length exp)-2)]).[e]
                      else
                        if d = 6 then
                           d <- 1
                        else
                           d <- d + 1
                      e <- e + 1
                      if x = 5 then
                        (guess 0)
                      else
                        (guess (x+1))
         |_ -> points <- points - 1
               e <- 1
               state <- "wrong"
               if d = 6 then
                  d <- 1
               else
                  d <- d + 1
               if x = 5 then
                 (guess 0)
               else
                 (guess (x+1))
让seq=[2;2;3;3;5;6]
设exp=[];[]
设可变点=0
设可变e=1
让可变状态=“”
设可变d=1
让rec猜测(x:int)=
将分数与
|100->“学习”
|_->将序列[x]与
|d->将(exp.[(List.length exp)-2)]与
|[]->如果state=“right”则
exp.[((List.length exp)-1)]@[d]
其他的

状态在匹配中使用
d
会导致使用该版本的
d
,而不是定义为可变值的
d

直接将值的名称更改为其他可用的名称
1


例如:
|d->match(exp.[((List.length exp)-2)]
可以变成
|1->match(exp.[((List.length exp)-2)]
在匹配中使用
d
会导致使用该版本的
d
而不是定义为可变值的
d

直接将值的名称更改为其他可用的名称
1


例如:
|d->match(exp.[((List.length exp)-2)]
可以变成
|1->match(exp.[((List.length exp)-2)]
d
match
表达式中被隐藏:
|d->match(exp.((List.length exp)-2)]with
对不起,我是哑巴了。但这到底是什么意思?或者你所说的“阴影”是什么意思?你已经创建了另一个名为
d
的值,当你试图对它进行变异时,它正确地说
d
是不可变的,可以称之为
d
以外的东西,或者直接使用
1
。哦!我明白你的意思!非常感谢!使用时应查看尾部递归函数:特别是有关累加器
d
的部分在
match
表达式中被隐藏:
|d->match(exp.[((List.length exp)-2)],与
非常抱歉,这是一个哑巴。但这到底是什么意思?或者你所说的“阴影”是什么意思?你已经创建了另一个名为
d
的值,当你试图对它进行变异时,它正确地说
d
是不可变的,可以称之为
d
以外的东西,或者直接使用
1
。哦!我明白你的意思!非常感谢!使用时应查看尾部递归函数:特别是有关累加器的部分