无法编译简单的 Ada Iterator 示例
Can't get simple Ada Iterator example to compile
我正在学习 Ada,我正在尝试让一个非常简单的循环工作(使用 Ada 2012 中的新迭代器语法)。我看不出有什么问题...
with Ada.Text_IO;
use Ada.Text_IO;
procedure Arrays is
type V is array (0 .. 1, 0 .. 2) of Natural;
A : V := ((10, 20, 30), (400, 500, 600));
begin
for E of A loop -- compiler error here!
E := E + 1;
end loop;
end Arrays;
我的编译命令是“$ gnatmake -gnaty -gnaty2 -gnat12 arrays”(为了迂腐的风格实施和启用 2012 功能)。
编译器错误是
arrays.adb:8:14: too few subscripts in array reference
(我在 Raspi 上使用 gnatmake 4.6)。
这段代码是从 John Barnes 的书 "Programming in Ada 2012" 第 120-121 页拼凑而成的。我已经尽可能地精简了这段代码,这就是它没有做太多事情的原因。据我所知,它与书中的示例完全相同。
我做错了什么?
使用嵌套数组。
procedure Iterator is
type rows is array (0 .. 2) of Natural;
type columns is array (0 .. 1) of rows;
A : columns := ((10, 20, 30), (400, 500, 600));
begin
for column of A loop
for E of column loop
E := E + 1;
put_line (e'img);
end loop;
end loop;
end Iterator;
我正在学习 Ada,我正在尝试让一个非常简单的循环工作(使用 Ada 2012 中的新迭代器语法)。我看不出有什么问题...
with Ada.Text_IO;
use Ada.Text_IO;
procedure Arrays is
type V is array (0 .. 1, 0 .. 2) of Natural;
A : V := ((10, 20, 30), (400, 500, 600));
begin
for E of A loop -- compiler error here!
E := E + 1;
end loop;
end Arrays;
我的编译命令是“$ gnatmake -gnaty -gnaty2 -gnat12 arrays”(为了迂腐的风格实施和启用 2012 功能)。 编译器错误是
arrays.adb:8:14: too few subscripts in array reference
(我在 Raspi 上使用 gnatmake 4.6)。
这段代码是从 John Barnes 的书 "Programming in Ada 2012" 第 120-121 页拼凑而成的。我已经尽可能地精简了这段代码,这就是它没有做太多事情的原因。据我所知,它与书中的示例完全相同。
我做错了什么?
使用嵌套数组。
procedure Iterator is
type rows is array (0 .. 2) of Natural;
type columns is array (0 .. 1) of rows;
A : columns := ((10, 20, 30), (400, 500, 600));
begin
for column of A loop
for E of column loop
E := E + 1;
put_line (e'img);
end loop;
end loop;
end Iterator;