Я пытаюсь использовать строку в выражении case, но она дает мне expected a discrete type. Found type Standard.String
Я понимаю, что строки не являются дискретными. Мне интересно, есть ли работа или нет. Вот мой код:Оператор case Ada со строками
function Is_Valid_Direction(Direction_To_Go : in String) return Integer is
Room : Integer := 0;
begin
--if (Direction_To_Go = "NORTH" or Direction_To_Go = "N") then
-- Room := Building(currentRoom).exits(NORTH);
--elsif (Direction_To_Go = "SOUTH" or Direction_To_Go = "S") then
-- Room := Building(currentRoom).exits(SOUTH);
--elsif (Direction_To_Go = "EAST" or Direction_To_Go = "E") then
-- Room := Building(currentRoom).exits(EAST);
--elsif (Direction_To_Go = "WEST" or Direction_To_Go = "W") then
-- Room := Building(currentRoom).exits(WEST);
--elsif (Direction_To_Go = "UP" or Direction_To_Go = "U") then
-- Room := Building(currentRoom).exits(UP);
--elsif (Direction_To_Go = "DOWN" or Direction_To_Go = "D") then
-- Room := Building(currentRoom).exits(DOWN);
--end if;
case Direction_To_Go is
when "NORTH" | "N" => Room := Building(currentRoom).exits(NORTH);
when "SOUTH" | "S" => Room := Building(currentRoom).exits(SOUTH);
when "EAST" | "E" => Room := Building(currentRoom).exits(EAST);
when "WEST" | "W" => Room := Building(currentRoom).exits(WEST);
when "UP" | "U" => Room := Building(currentRoom).exits(UP);
when "DOWN" | "D" => Room := Building(currentRoom).exits(DOWN);
when others => Room := 0;
end case;
return Room;
end Is_Valid_Direction;
Прокомментированный раздел выполняет именно то, что я хочу, но с операторами if. Я просто пытаюсь понять, возможно ли это с помощью case case.
No. Ada is not Java. – ajb
Это может помочь подумать о вещах «по-другому» - начать с внутренних дел, а затем перейти к пользовательскому интерфейсу - точнее, подумать о проблеме с точки зрения типов. http://blog.kickin-the-darkness.com/2007/08/fundamental-theory-of-ada.html – Shark8