如何在Oz中的List中绑定未绑定的值

时间:2015-04-06 13:23:50

标签: oz mozart

我们说我们有以下代码:

local L in
    L = {List.make 10 $}
    % Bind nth element to something here
end

如何设置任何这些未绑定的值? Oz List Documentation并没有对此有所了解。我找到的唯一相关问题是:How do you change an element in a list in Oz?答案没有为我编译,也没有找到我如何编译它。

2 个答案:

答案 0 :(得分: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 :(得分: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元素,但不是编程解决方案,因为您可能知道每个列表都是缺点(head | tail),因此您可以使用L.1访问第一个元素,使用L.2.1访问第二个元素,依此类推.. 最后,您不需要在第二行中输入“$”,因为您已经将List.make的结果分配给L。

相关问题