如何在 Oz 中创建列表?
我正在尝试使用以下代码在 Oz 中创建一个列表:
local Loop10 Xs in
proc {Loop10 I}
Xs={List.append Xs I}
if I == 10 then skip
else
{Browse I}
{Loop10 I+1}
end
{Browse Xs}
end
{Loop10 0}
end
Mozart 编译器 显示代码已被接受,但没有打开浏览窗口。我想做的就是在奥兹国创建一个列表。
代码有什么问题吗?
I'm trying to create a list in Oz using the following code:
local Loop10 Xs in
proc {Loop10 I}
Xs={List.append Xs I}
if I == 10 then skip
else
{Browse I}
{Loop10 I+1}
end
{Browse Xs}
end
{Loop10 0}
end
The Mozart compiler shows that the code is accepted, but no Browse window opens up. All I'm trying to do is create a list in Oz.
What's wrong with the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定这就是您想要的,但要创建 X 和 Y(含)之间的所有整数的列表,您可以执行以下操作:
Not sure that that's what you want, but to create a list of all whole numbers between X and Y (inclusive) you could do:
另外,您没有获得任何浏览器窗口的原因是因为评估线程由于这一行而挂起:
正如前面提到的,变量只能分配一次,但这一行还有其他问题。
您尝试将
Xs
附加到 I,但Xs
仍未绑定。因此,线程将挂起,直到将值分配给 Xs。以交互方式输入:
正如您所看到的,没有任何反应,也没有浏览器打开。现在输入:
由于
Xs
被绑定,它会解锁第一个评估“线程”,并且浏览器将弹出。PS 抱歉回复晚了,我只是对奥兹感兴趣:P
Also the reason why you don't get any browser window is because the evaluation thread suspend due to this line:
As it was previously mentioned a variable can only be assigned once but there is something else that is wrong with this line.
You attempt to append
Xs
to I butXs
is still unbound. The thread thus suspends until a value has been assign toXs
.Enter this interactively:
As you see nothing happens, no browser opens. Now enter this:
Since
Xs
becomes bound it unlocks the first evaluation "thread" and the browser will pop-up.P.S. Sorry for the late answer, I just got interested in Oz :P