本文介绍了如何在Oz中创建列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码在 Oz 中创建一个列表:

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

Mozart编译器显示该代码已被接受,但没有打开浏览"窗口.我要做的就是在Oz中创建一个列表.

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.

代码有什么问题?

推荐答案

不确定这就是您想要的,但是要创建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:

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

这篇关于如何在Oz中创建列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 12:08