Gem #22: Ada Speaks Many Languages

by Robert DewarVasiliy FofanovFranco GasperoniYang Zhang—AdaCoreAdaCoreAdaCore

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.adbhappy_new_year_cn_en.adbhappy_new_year_ru_en.adbhappy_new_year_ru_ru.adbhappy_new_year_us_en.adb

About the Author

Dr. Robert Dewar is co-founder, President and CEO of AdaCore and Emeritus Professor of Computer Science at New York University. With a focus on programming language design and implementation, Dr. Dewar has been a major contributor to Ada throughout its evolution and is a principal architect of AdaCore’s GNAT Ada technology. He has co-authored compilers for SPITBOL (SNOBOL), Realia COBOL for the PC (now marketed by Computer Associates), and Alsys Ada, and has also written several real-time operating systems, for Honeywell Inc. Dr. Dewar has delivered papers and presentations on programming language issues and safety certification and, as an expert on computers and the law, he is frequently invited to conferences to speak on Open Source software, licensing issues, and related topics.Franco Gasperoni is co-founder and Managing Director of AdaCore in Europe. He has been involved with Ada both commercially and technically since 1991. Franco has an engineering degree from the Ecole des Mines de Paris, France and a PhD in Computer Science from New York University, USA. While at the Ecole des Mines, Franco worked with Maurice Allais, the French Economics Nobel laureate. Franco has lectured and conducted research at New York University and at the Ecole des Telecommunications (ENST), in Paris. Franco has published over 25 papers.
Last Updated: 10/13/2017
Posted on: 12/17/2007