comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: "Use" and "=" for Tags (was: Re: Instantiating private types with discriminants?)
Date: Tue, 09 May 2006 19:57:39 GMT
Date: 2006-05-09T19:57:39+00:00	[thread overview]
Message-ID: <Tu68g.722760$084.49925@attbi_s22> (raw)
In-Reply-To: <gZ18g.28779$Nb2.521756@news1.nokia.com>

> 
>    --  problem line:
>    if Var_A'Tag = Type_A'Tag then
>       Ada.Integer_Text_IO.Put ( Type_A (Var_A.all).Data);
>    elsif Var_A'Tag = Type_B'Tag then
>       Ada.Float_Text_IO.Put ( Type_B (Var_A.all).Data);
>    end if;

You've received some specific solutions, but no general discussion of 
why this doesn't work. The function "=" you're trying to call is defined 
in Ada.Tags, and not directly visible here. You can make it directly 
visible with a "use" clause for Ada.Tags, as you've already discovered, 
or with a "use type" clause for Ada.Tags.Tag. You can use prefix 
notation to access it [Ada.Tags."=" (...)]. The subtype membership 
operation {"in"} is not a subprogram and is always visible, like 
assignment (":="). Finally, you have the Ada-83 solution to avoiding 
"use", renaming:

function "=" (Left : Ada.Tags.Tag; Right : Ada.Tags.Tag) return Boolean
renames Ada.Tags."=";
...
if This_Tag = That_Tag then

The operators for the predefined types, being in Standard, are always 
directly visible, so you don't encounter this problem with them. For the 
most part, though, well designed Ada deals with user-defined types, so 
understanding this concept is useful.

-- 
Jeff Carter
"Apart from the sanitation, the medicine, education, wine,
public order, irrigation, roads, the fresh water system,
and public health, what have the Romans ever done for us?"
Monty Python's Life of Brian
80



      parent reply	other threads:[~2006-05-09 19:57 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-09 13:17 Instantiating private types with discriminants? rick H
2006-05-09 13:45 ` Georg Bauhaus
2006-05-09 14:06   ` rick H
2006-05-09 13:56 ` Ludovic Brenta
2006-05-09 14:24   ` rick H
2006-05-09 19:48     ` Ludovic Brenta
2006-05-09 14:05 ` Dmitry A. Kazakov
2006-05-09 14:48 ` rick H
2006-05-09 15:20   ` Jerry Petrey
2006-05-09 15:42     ` rick H
2006-05-09 15:53   ` Avoiding use Ada.Tags (was Re: Instantiating private types with discriminants?) Alex R. Mosteo
2006-05-09 16:01   ` Instantiating private types with discriminants? Dmitry A. Kazakov
2006-05-10  7:42     ` rick H
2006-05-10  9:09       ` Ludovic Brenta
2006-05-10 11:49         ` Georg Bauhaus
2006-05-10 13:44         ` rick H
2006-05-10 14:21           ` Ludovic Brenta
2006-05-10 15:10             ` rick H
2006-05-10 15:45               ` Ludovic Brenta
2006-05-10 14:41           ` Dmitry A. Kazakov
2006-05-10 15:34             ` rick H
2006-05-10 19:01               ` Georg Bauhaus
2006-05-10 19:05                 ` Ludovic Brenta
2006-05-10 21:52                   ` Rick H
2006-05-11  1:17                     ` Jeffrey R. Carter
2006-05-11  7:44                     ` Dmitry A. Kazakov
2006-05-11  8:27                       ` rick H
2006-05-11 10:28                         ` Dmitry A. Kazakov
2006-05-11 15:59                           ` Robert A Duff
2006-05-12  7:37                             ` Dmitry A. Kazakov
2006-05-12  9:24                               ` Georg Bauhaus
2006-05-12 12:40                                 ` Dmitry A. Kazakov
2006-05-12 18:25                                   ` Randy Brukardt
2006-05-09 19:57   ` Jeffrey R. Carter [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox