comp.lang.ada
 help / color / mirror / Atom feed
From: jm21@prism.gatech.EDU (Jim Marks)
Subject: Re: Unusual "use" semantics
Date: 8 Aug 90 22:37:00 GMT	[thread overview]
Message-ID: <12342@hydra.gatech.EDU> (raw)
In-Reply-To: 20@polymnia.tsd.arlut.utexas.edu

In article <20@polymnia.tsd.arlut.utexas.edu> fred@polymnia.tsd.arlut.utexas.edu (Fred Hosch) writes:
>My Ada compiler complains about the relation on the fourth line of the
>following
>
>	with TEXT_IO;
>	procedure TEST is
>	begin
>	    if TEXT_IO.COL = 1 then
>...
>
>reporting: no operator visible for positive_count "=" universal integer.
>
>If I add a context clause "use TEXT_IO;" it compiles successfully.
>

This is a result of the strong typing and operator overloading of Ada.  
The "=" operator you have visible can take two integer type arguments.  
However, the return value of TEXT_IO.COL is of type POSITIVE_COUNT, which 
is a subtype of type COUNT, declared in the Text_IO package (LRM 14.3.10).  
This type has its own "=" operator implicitly declared for it in Text_IO.
When you include the "use" clause for Text_IO, then the "=" operator for 
this type (COUNT) is then visible (in this case, the "1" is considered 
of this type so that it matches).  You could also do the following:

if integer(Text_IO.Col) = 1 then ...   which converts the return value
				to integer, OR

if Text_IO."=" ( Text_IO.Col , 1 ) then ...   which is UGLY.

I've had this problem many times when I don't think about it in advance.
This is a good application of the "use" clause, even though some coding
standards discourage (or prohibit) the use of "use" clauses.

-- 
Jim Marks   		   | Georgia Tech Research Institute
Compuserve: 72310,2410     | Concepts Analysis Laboratory
Internet:   jm21@prism.gatech.edu -or- jmarks@gtri01.gatech.edu

  reply	other threads:[~1990-08-08 22:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-08-08 21:21 Unusual "use" semantics Fred Hosch
1990-08-08 22:37 ` Jim Marks [this message]
1990-08-09 12:45   ` Mike Wever
1990-08-09 15:59     ` Richard Pattis
1990-08-09  7:54 ` Rik Palo
1990-08-09 14:51 ` Allan Doyle
1990-08-09 16:15 ` Kurt Olender
1990-08-10 17:44   ` Alan Kaplan
replies disabled

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