Ada中的初始化数组边界

Che*_*err 0 java arrays types linked-list ada

在ada中编写双循环链表的包时遇到问题.我专门编写了一个函数,它将获取我的DCLL并以数组形式返回它的内容.在我的spec文件中,我创建了这样的类型

type ListArray is array(Integer range <>) of Integer;
Run Code Online (Sandbox Code Playgroud)

我的问题是,当客户端调用我的包时,我不断收到"长度检查失败"错误.这是客户端程序(部分)

procedure tester is

   LL : sorted_list.List;
   larray : sorted_list.ListArray(1..sorted_list.length(LL));

   begin
   sorted_list.Insert(LL, 5);
   larray:= sorted_list.toArray(LL);
   end;
Run Code Online (Sandbox Code Playgroud)

我知道这是失败的,因为当我定义larray并将其设置为长度时,长度为0,因为LL还没有任何内容.在java中,我只是在插入后在代码体中初始化数组,但似乎在ada中我不能这样做(或者至少我不知道如何)无论如何在ada中创建数组而不定义绑定然后在插入后定义正文中的边界?

我希望我能够很好地解释我的问题,让你明白.谢谢.

ajb*_*ajb 6

procedure tester is

    LL : sorted_list.List;

begin
    sorted_list.Insert(LL, 5);
    declare
        larray : sorted_list.ListArray(1..sorted_list.length(LL));
    begin
        larray := sorted_list.toArray(LL);
        -- code that uses larray must be in this block
    end;
end;
Run Code Online (Sandbox Code Playgroud)

要么

procedure tester is

    LL : sorted_list.List;

begin
    sorted_list.Insert(LL, 5);
    declare
        larray : sorted_list.ListArray := sorted_list.toArray(LL);
            -- no need to specify the bounds, it will take them from the bounds
            -- of the result returned by toArray
    begin
        -- code that uses larray must be in this block
    end;
end;
Run Code Online (Sandbox Code Playgroud)

declare几点需要注意:(1)块中的声明(以...开头)是在执行语句的位置进行计算的(实际上,块一种语句),因此它将使用LL已经存在的语句.在那时设立.(2)变量larray仅在您声明它的块内可见.