如何在Oz中绑定列表中的未绑定值
假设我们有以下代码:如何在Oz中绑定列表中的未绑定值,oz,mozart,Oz,Mozart,假设我们有以下代码: local L in L = {List.make 10 $} % Bind nth element to something here end 如何设置这些未绑定的值?警方没有透露这件事。我发现的唯一相关问题是:答案在哪里没有为我编译,我也没有找到如何编译它。我实际上能够使用来自的东西让它工作 declare Temp Index Value L in L = {List.make 10 $} Index = %Index to be bound Va
local L in
L = {List.make 10 $}
% Bind nth element to something here
end
如何设置这些未绑定的值?警方没有透露这件事。我发现的唯一相关问题是:答案在哪里没有为我编译,我也没有找到如何编译它。我实际上能够使用来自的东西让它工作
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
$}
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
您将获得正确的输出[\uu1\uuu1]
。您也可以直接访问en元素,但这不是一个编程解决方案,因为您可能知道每个列表都是cons(head | tail),因此您可以使用L.1访问第一个元素,使用L.2.1访问第二个元素,依此类推。。
最后一件事,您不需要将“$”放在第二行,因为您已经在将List.make的结果分配给L.或者,您也可以只执行
{Nth L Index}=Value
@wmeyer到底是什么!:p我尝试了这个,但失败了,这就是为什么我最终采用了这个疯狂的实现。。一定是在代码中的其他地方出错了。。谢谢你的提示:D!