Reputation: 2867
I am making a program in Ada for Data Structures and Algorithms class.
My current problem is the error 'actual for "this" must be a variable' I did some looking around and I read about it being because of in out mode, but I'm not entirely grasping why it's happening to me I guess.
The Examples I seen made sense but I guess since it's my coding I'm just not seeing it?
Procedure AddUnmarked(g:Grid; this:Linked_List_Coord.List_Type; c:Cell) is
cNorth : Cell := getCell(g, North(c));
cEast : Cell := getCell(g, East(c));
cSouth : Cell := getCell(g, South(c));
cWest : Cell := getCell(g, West(c));
Begin
if CellExists(g, cNorth) and not cNorth.IsMarked then
Linked_List_Coord.Append(this, cNorth.Coords);
elsif CellExists(g, cEast) and not cEast.IsMarked then
Linked_List_Coord.Append(this, cEast.Coords);
elsif CellExists(g, cSouth) and not cSouth.IsMarked then
Linked_List_Coord.Append(this, cSouth.Coords);
elsif CellExists(g, cWest) and not cWest.IsMarked then
Linked_List_Coord.Append(this, cWest.Coords);
end if;
End AddUnmarked;
before "this" is passed to the function it is a Linked_List of my self defined type Coord (2 integers). It is initialized and has had a Coordinate pair added to it before the list is passed to the function above in my code.
Upvotes: 1
Views: 5541
Reputation: 44804
In Ada, subroutine parameters all have a usage mode associated with them. The available modes are in
, out
, and in out
*. If you don't specify a mode, (like you didn't in your code), then it defaults to in
only.
The modes specify what you can do with that parameter on the inside of the subprogram. If you want to read a value passed in from outside the routine, it must have in
on it. If you want to write to the parameter (and/or possibly have it read outside the routine), then it must have out
on it.
Since none of your parameters have out
on them, you cannot write to any of them.
(* - There's another possible mode: access
, but that's an advanced topic).
Upvotes: 2
Reputation: 4198
What it means is that the list cannot be modified unless you are passing it as a modifiable parameter, that is, in out
.
To elaborate, think of LIST_TYPE
as being a handle to a tagged-type object; in order to ensure that LIST_TYPE
is valid you need to pass it in via an in
parameter (or create/manipulate a local object), but to pass out your results you need an out
parameter.
So, in order to do your operations on an already-existing object {and get the results back} you need in out
.
Upvotes: 6