Here's an example of a formal_object_declaration:
Maximum_Size : Integer;
Here's the syntax for defining a value or variable as a formal object in BNF format:
formal_object_declaration ::= identifier_list ":" [ "in" | "in out" ] type_name [ ":=" default_expression ] ";"
We've already seen an example of a formal type declaration. Formal types specify the name of a type and what ``kind of type'' is permitted. A formal type declaration specifies the "minimum" or "worst case" kind of type that is required. The most minimal type in Ada is called a "limited private" type. This is the "worst case" because the keyword "private" means that you may not know anything about how it's implemented, and "limited" means that there might not be assignment or equality operations defined for it.
A formal type declaration has the following syntax (this is actually highly simplified; many more things are permitted):
formal_type_declaration ::= "type" defining_identifier "is" formal_type_definition ";" formal_type_definition ::= ["tagged"] ["limited"] "private" | "(<>)"
Let's look at some examples, with their meaning written beside them:
type Item is limited private; -- Item can be any type. type Item is private; -- Item can be any type that has assignment -- (:=) and equal-to (=) operation. type Item is tagged limited private; -- Item can be any tagged type. type Item is tagged private; -- Item can be any tagged type with :=. type Item is (<>); -- Item can be any discrete type, including -- Integer and Boolean.
In the next section we'll look at an example that should make these things clearer.
If you want to create a generic with a formal type named Unit that could be any type at all, how would you declare it?
|Go back to the previous section||Skip to the next section||Go up to lesson 11 outline|
David A. Wheeler (email@example.com)
The master copy of this file is at
The master copy of this file is at "http://www.adahome.com/Tutorials/Lovelace/s11s2.htm".