2015-04-06 17 views

回答

0

我實際上可以使用Oz List Documentation中的某些東西來使其工作!

declare Temp Index Value L in 
L = {List.make 10 $} 

Index = %Index to be bound 
Value = %Value for bound 

Temp = {List.mapInd L 
    fun {$ I B} 
     if I == Index then 
     B = Value 
     else 
     B 
     end 
    end 
$} 
+1

或者,您也可以只執行「{Nth L Index} =值'。 – wmeyer 2015-04-06 14:49:19

+0

@wmeyer什麼鬼! :p我嘗試過但是失敗了,這就是爲什麼我最終與這個瘋狂的實現一起使用的原因。一定是在代碼中的其他地方犯了一個錯誤。謝謝提示:D! – Spyral 2015-04-06 16:11:17

0

wmeyer是正確的,完整的實現可以是例如:

declare 
local L I V in 
    L = {List.make 10} 
    I=5 %index to be bound 
    V=1 %value for bound 
    {List.nth L I}=V 
    {Browse L} 
end 

你會得到正確的輸出[_ _ _ _ 1 _ _ _ _ _]。您也可以直接訪問en元素,但不是一個以編程方式的解決方案,因爲您可能知道每個列表都是cons(頭尾),因此您可以使用L.1訪問第一個元素,第二個元素使用L.2.1,等等.. 最後一件事,因爲您已經將List.make的結果分配給了L,所以不需要在第二行輸入「$」。