Beaujolais Effect - Background

Background

The Ada programming language allows source code to be broken up into library packages containing definitions of data and algorithms that can be used by programs or other library packages. The definitions in a package are made visible by a with clause. For example, if the line –

with Ada.Text_IO;

appears at the top of the source code for a program or package then the data, procedures, and functions declared in the library package Ada.Text_IO can be invoked within that source code. This is the implementation of the namespace concept for Ada.

Thus a program that has the with Ada.Text_IO; directive can "see" the definitions there, and in order to invoke the New_Line procedure in Ada.Text_IO it can be referred to by name,

Ada.Text_IO.New_Line;

and similarly with procedures or functions that require arguments, or with reads/writes to any variables declared in the Ada.Text_IO package.

However, such fully specified names can become quite verbose, so the language standard also supports a use clause that tells the compiler to search the contents of the package when trying to identify names that occur in the source code. Thus if both the lines –

with Ada.Text_IO; use Ada.Text_IO;

appear at the top of a program, the New_Line procedure in the package Ada.Text_IO is not only visible to the program, but can be invoked by the abbreviated form –

New_Line;

because the use clause tells the compiler what package contains the definition.

However, ambiguity arises if more than one package defines a New_Line procedure with the same or similar parameter profiles. If the program does not resolve the ambiguity, the compiler should reject the program with an error message. Here is an example:

package A is procedure New_Line (Number_Of_Lines : in Positive := 1); end A; with A; use A; with Ada.Text_IO; use Ada.Text_IO; procedure Ambiguous is begin New_Line; -- error end Ambiguous;

In the example above, the call is ambiguous because it could correspond to either Ada.Text_IO.New_Line or A.New_Line with the default parameter value. There are two ways to resolve the ambiguity. One is to specify the package name, and the other is to specify the parameter name explicitly, if the subprogram to call has parameters. The four examples below all resolve the ambiguity.

Ada.Text_IO.New_Line; A.New_Line; New_Line (1); New_Line (Number_Of_Lines => 1);

Read more about this topic:  Beaujolais Effect

Famous quotes containing the word background:

    ... every experience in life enriches one’s background and should teach valuable lessons.
    Mary Barnett Gilson (1877–?)

    Pilate with his question “What is truth?” is gladly trotted out these days as an advocate of Christ, so as to arouse the suspicion that everything known and knowable is an illusion and to erect the cross upon that gruesome background of the impossibility of knowledge.
    Friedrich Nietzsche (1844–1900)

    Silence is the universal refuge, the sequel to all dull discourses and all foolish acts, a balm to our every chagrin, as welcome after satiety as after disappointment; that background which the painter may not daub, be he master or bungler, and which, however awkward a figure we may have made in the foreground, remains ever our inviolable asylum, where no indignity can assail, no personality can disturb us.
    Henry David Thoreau (1817–1862)