[英]Is there a way to quickly initialize an array with a sequence of values in Ada?
For instance if I want to initialize an array of elements like so:例如,如果我想像这样初始化一个元素数组:
someArray : array(1..10) of Integer := (2,4,6,8,10,12,14,16,18,20);
Is there a short-hand way or some mechanism to do this quicker?有没有一种捷径或某种机制可以更快地做到这一点?
Matlab and python has for example the linspace
function that returns a sequence of equally spaced numbers. Matlab 和 python 有例如
linspace
function 返回等间距数字序列。 Is there a similar functionality for Ada that works for any array type of any length? Ada 是否有适用于任何长度的任何数组类型的类似功能?
I can make a generic function to do this, but that would require separate initialization for each individual array type and that seems a bit cumbersome for a function that will essentially be used once for each array type.我可以制作一个通用的 function 来执行此操作,但这将需要为每个单独的数组类型单独初始化,并且对于基本上将对每个数组类型使用一次的 function 来说这似乎有点麻烦。
Ada 2022 (eg GCC 12 with -gnat2022
) allows Ada 2022(例如 GCC 12 和
-gnat2022
)允许
package Aggregates is
type A is array (Integer range <>) of Integer;
V : A := (for J in 1 .. 10 => J * 2);
end Aggregates;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.