Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Demo for http://stackoverflow.com/q/13851524/827263 "How to assign all elements but one in ada?"
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Foo is
Element_To_Ignore : Integer := 3;
type Array_Of_Integer is array(Positive Range <>) of Integer;
A : Array_Of_Integer := (5,3,2,6);
B : Array_Of_Integer
:= A(A'First .. Element_To_Ignore-1) &
A(Element_To_Ignore+1 .. A'Last);
procedure Print_Array(Name: String; A: Array_Of_Integer) is
begin
Put(Name);
Put(": (");
Put(A'First, Width => 0);
Put("..");
Put(A'Last, Width => 0);
Put(") = (");
for I in A'Range loop
Put(A(I), Width => 0);
if (I < A'Last) then
Put(", ");
end if;
end loop;
Put_Line(")");
end Print_Array;
begin
for Element_To_Ignore in A'First - 3 .. A'Last + 3 loop
Put("Element_To_Ignore = "); Put(Element_To_Ignore, Width => 0); Put(" : ");
begin
declare
B : Array_Of_Integer
:= A(A'First .. Element_To_Ignore-1) &
A(Element_To_Ignore+1 .. A'Last);
begin
Print_Array("B", B);
end;
exception
when Constraint_Error =>
Put_Line("Constraint_Error");
end;
end loop;
end Foo;
Element_To_Ignore = -2 : Constraint_Error
Element_To_Ignore = -1 : Constraint_Error
Element_To_Ignore = 0 : B: (1..4) = (5, 3, 2, 6)
Element_To_Ignore = 1 : B: (2..4) = (3, 2, 6)
Element_To_Ignore = 2 : B: (1..3) = (5, 2, 6)
Element_To_Ignore = 3 : B: (1..3) = (5, 3, 6)
Element_To_Ignore = 4 : B: (1..3) = (5, 3, 2)
Element_To_Ignore = 5 : B: (1..4) = (5, 3, 2, 6)
Element_To_Ignore = 6 : Constraint_Error
Element_To_Ignore = 7 : Constraint_Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.