Ada: 'strings are delimited by double quote character' compile error

Viewed 168

This is all 30 lines of my program:

with Ada.Containers.Hashed_Maps;
with Ada.Strings;
with Ada.Strings.Wide_Hash;
with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;

procedure encoder is
    -- Copied this function from GitHub.
    function Character_Hashed (id: Wide_Character) return Ada.Containers.Hash_Type is
        str: Wide_String(1..1);
    begin
        str(1) := id;
        return Ada.Strings.Wide_Hash(str);
    end Character_Hashed;

    package My_Dict is new Ada.Containers.Hashed_Maps (
        Key_Type => Wide_Character,
        Element_Type => Wide_Character,
        Hash => Character_Hashed,
        Equivalent_Keys => "="
    );

    encoding: My_Dict.Map;
    to_encode: Wide_Character;
    encoded: Wide_Character;
begin
    encoding.insert('a', 'α'); -- This line is where the compile error happens.
--    encoding.insert('a', 'b'); <-- Swapping it with this line allows the code to compile.
    to_encode := 'a';
    Put_Line("Encoded:");
end encoder;

At first glance, the solution seems obvious: it wants be to change one or both of 'a' and 'α' to "a" and/or "α". But this won't do the trick; the map, after all, is supposed to map from a character to character, and if I put in double quotes, I get a compilation error to that effect.

Any idea where I'm going wrong?

1 Answers

'α' is not part of the default character set (Ada.Characters.Latin_1). Try Wide_Character or Wide_Wide_Character for Unicode characters.

Related