Tutorial by Examples

A literal inside a enumeration is a discrete type so we can use attribute Image to find out which literal it is as text form. Notice that this prints out the same word as in the code (but in upper case). with Ada.Text_IO; use Ada.Text_IO; procedure Main is type Fruit is (Banana, Pear, Orang...
Instead of attribute Image and Ada.Text_IO.Put on enumeration literals we can only use the generic package Ada.Text_IO.Enumeration_IO to print out the literals. with Ada.Text_IO; use Ada.Text_IO; procedure Main is type Fruit is (Banana, Pear, Orange, Melon); package Fruit_IO is new Enume...
Attribute Image capitalizes all characters of enumeration literals. The function Case_Rule_For_Names applies upper case for the first character and makes the rest lower case. with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants; with Ada.Strings.Fixed...
Combining change of character case with Enumeration_IO and using a text buffer for the image. The first character is manipulated in place. with Ada.Text_IO; use Ada.Text_IO; with Ada.Characters.Handling; use Ada.Characters.Handling; procedure Main is type Fruit is (Banana, Pear, Orange, Me...

Page 1 of 1