如何在 Oz 中创建列表?

发布于 2024-08-05 17:10:48 字数 491 浏览 3 评论 0原文

我正在尝试使用以下代码在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情域 2024-08-12 17:10:48

不确定这就是您想要的,但要创建 X 和 Y(含)之间的所有整数的列表,您可以执行以下操作:

local
   fun {Loop From To}
      if From > To
      then nil
      else From | {Loop From+1 To}
      end
   end
in
   {Browse {Loop 0 10}} % Displays: [0,1,2,3,4,5,6,7,8,9,10]
end

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:

local
   fun {Loop From To}
      if From > To
      then nil
      else From | {Loop From+1 To}
      end
   end
in
   {Browse {Loop 0 10}} % Displays: [0,1,2,3,4,5,6,7,8,9,10]
end
画离情绘悲伤 2024-08-12 17:10:48

另外,您没有获得任何浏览器窗口的原因是因为评估线程由于这一行而挂起:

Xs={List.append Xs I}

正如前面提到的,变量只能分配一次,但这一行还有其他问题。
您尝试将 Xs 附加到 I,但 Xs 仍未绑定。因此,线程将挂起,直到将值分配给 Xs。

以交互方式输入:

declare Xs in
{Browse {List.append Xs [2 3 4]}}

正如您所看到的,没有任何反应,也没有浏览器打开。现在输入:

Xs= [1]

由于 Xs 被绑定,它会解锁第一个评估“线程”,并且浏览器将弹出。

PS 抱歉回复晚了,我只是对奥兹感兴趣:P

Also the reason why you don't get any browser window is because the evaluation thread suspend due to this line:

Xs={List.append Xs I}

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 but Xs is still unbound. The thread thus suspends until a value has been assign to Xs.

Enter this interactively:

declare Xs in
{Browse {List.append Xs [2 3 4]}}

As you see nothing happens, no browser opens. Now enter this:

Xs= [1]

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文