…
type dimension is (row, col);
function A (num: …; dim: in out dimension) return integer is
…
case dim is
when row => return my_array(num).row;–? ok
when col => A (… ) ;
– ^ returns my_array(num).col
end case;
------------------------------------ use example
my_row := A(num:num_range; dim:in out dimension);
…
with this case statement, can I put a single line of code, rather than a sub program call after the =>?
How odd.
I think one of the most natural examples would be writing a simple virtual machine.
Type Instruction is (Add, Sub, Done);
Type VM is limited private;
Procedure Execute( Object : in out VM );
Procedure Load ( Object : in out VM;
Input : in out Root_Stream_Type'Class );
-- …
Procedure Execute( Object : in out VM ) is
Finished : Boolean:= False;
Begin
Run:
Loop
case Object.Program(Object.Program_Counter) is
when Add =>
declare
Left : Integer renames Object.Registers(1);
Right : Integer renames Object.Registers(2);
begin
Left:= Left + Right;
exception
when Constraint_Error => Object.Flags( Overflow ):= True;
end;
when Sub => -- Same, but for "-".
when Done => Finished:= True;
end case;
Exit Run when Finished;
Object.Program_Counter:= Positive'Succ( Object.Program_Counter );
End Loop Run;
End Execute;
That is technically not a case statement.
It’s one of the “expression statements” — the way to understand the difference is whether or not it returns a value: like a procedure, a [normal] statement does not return a value, but like a function an expression resolves to a value.