Gem #22: Ada Speaks Many Languages
by Robert Dewar, Vasiliy Fofanov, Franco Gasperoni, Yang Zhang —AdaCore
Let's get started…
The only characters allowed in an Ada 83 program (for strings, comments, and identifiers) were 7-bit ASCII symbols. That was annoying. In Ada 83 we could not write:
S : String : = "à la carte";
and even less write:
À_La_Carte : Boolean := False;
That was - how shall we put it - a "set menu" - view of things :)
An amendment changed this situation to 8-bit characters during the lifetime of Ada 83. Ada 95 made this 8-bit change clearer and more official, designating ISO Latin-1 as the character set. So the above are both legal in Ada 95. Ada 95 also introduced 16-bit ISO 10646 support in the form of Wide_Character. One can write in Ada 95:
My_Favorite_Pie : String := "π"; -- :)
but an implementation did not have to allow 16-bit characters in identifiers and comments, and Ada 95 did not mandate the acceptance of the following:
π : constant := 3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511; -- Can't eat this one :)
although the GNAT technology for Ada 95 allows full 16-bit characters in identifiers and comments.
Ada 2005 is the ultimate in terms of openness: the full 32-bit ISO-10646 character set is supported and use of π (for instance) in identifiers, comments, and strings is allowed in an Ada 2005 program. As a matter of fact the package Ada.Numerics in Ada 2005 now contains:
Pi : constant := 3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511; π : constant := Pi;
To demonstrate the use of the full 32-bit ISO-10646 character set in Ada 2005 programs we have written a couple of programs in English, Russian, and Chinese. These programs take an ISO date ranging from 1983 to 2019 and print the date in the local format. Each program wishes you a happy new year if the date entered matches the local new year date. All file names are of the form:
happy_new_year_{locale}_en.adb
where {locale} is a 2 letter sequence indicating the country for which the program has been written (e.g. "us" for the US, "cn" for China, "ru" for Russia) and en the language in which the program has been written (e.g. "en" for English, "cn" for Chinese, "ru" for Russian). For instance "happy_new_year_cn_en.adb" is the program for China written in English, while "happy_new_year_cn_cn.adb" is the program for China written in Chinese. Having a program in English for China allows non Chinese speakers to understand what the program does and perhaps learn some Chinese :)
To compile the Ada programs provided with this gem we suggest that you use options -gnatW8 -gnat05.
Enjoy... Happy Holidays and Happy New Year :)
Related Source Code
Ada Gems example files are distributed by AdaCore and may be used or modified for any purpose without restrictions.
happy_new_year_cn_cn.adb