0
我在做什麼錯?舉例來說,這應該返回10:Scala無狀態函數
{ val (get, set) = getAndSet (5); set (10); get() }
val getAndSet : Int => (() => Int, Int => Unit) = {
var s : Int = 0
val get :() => Int =() => {
val z = s;
s = s + 1;
z
}
val set : Int => Unit = (x:Int) => {
s = x
}
x => (get, set)
}
我的道歉,我沒有看到我的輸入錯誤。我的代碼編譯雖然但它沒有通過測試。我也認爲「s = s + 1;」應該是平等的,我怎麼會把它變成平等?它會像「s.Equal(s + 1)」? – yeny314