0

I'm approaching the Ada language. I wrote this simple program that loops over an array and increments every single value, but the compiler gives me an error of type:

hello.adb:8:07: left hand side of assignment must be a variable   

The program in question is this:

with Ada.Text_IO;
procedure hello is
type myArrayDefinition is array (1 .. 10) of integer;
myArray : constant myArrayDefinition := (1 => 3, others => 2);
begin
   for A in 1 .. 10 loop
     myArray(A) := myArray(A) + 1;
   end loop;
end hello;

Could anyone help me to understand the problem?

2
  • 10
    The error message tells you exactly what's wrong. myArray isn't a variable, it's a constant. Commented Nov 24, 2016 at 17:41
  • 1
    Just in case you have experience with some other language: an array object in Ada is not a reference, it is a true object. As noted, yours is constant, and then is constant as a whole. That's true for other objects as well. Commented Nov 25, 2016 at 19:05

1 Answer 1

2

You can't modify the value of a constant. There are no special problems related to modifying the values of arrays.

Sign up to request clarification or add additional context in comments.

1 Comment

IOW: The compiler could have said: "The target of an assignment must be a variable, not a constant."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.