为什么变量不是不可变的?
Why is a variable not immutable?
为什么这段代码中的 varx 不是不可变的?
y = { g = 'a' }
z = { g = 1 }
varx = foo y
varx = foo z
有人知道吗?谢谢
我猜测这段代码是在 Elm REPL 中执行的。不可变变量的行为略有不同。来自 Beginning Elm 书:
https://elmprogramming.com/immutability.html
The repl works a little differently. Whenever we reassign a different value to an existing constant, the repl essentially rebinds the constant to a new value. The rebinding process kills the constant and brings it back to life as if the constant was never pointing to any other value before.
使用Elm make 以普通方式编译Elm 代码时,此代码会导致错误。
为什么这段代码中的 varx 不是不可变的?
y = { g = 'a' }
z = { g = 1 }
varx = foo y
varx = foo z
有人知道吗?谢谢
我猜测这段代码是在 Elm REPL 中执行的。不可变变量的行为略有不同。来自 Beginning Elm 书:
https://elmprogramming.com/immutability.html
The repl works a little differently. Whenever we reassign a different value to an existing constant, the repl essentially rebinds the constant to a new value. The rebinding process kills the constant and brings it back to life as if the constant was never pointing to any other value before.
使用Elm make 以普通方式编译Elm 代码时,此代码会导致错误。