comp.lang.ada
 help / color / mirror / Atom feed
* How do I avoid 'use' in this case?
@ 1993-03-11 16:39 Val Kartchner
  1993-03-11 18:17 ` MILLS,JOHN M.
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Val Kartchner @ 1993-03-11 16:39 UTC (permalink / raw)


I know that the usage of 'use' is discouraged.  I generally agree, but I do
not see a way around it in this case.  Is there something that I'm missing?

We have a package called 'FIELD_DEF' which (among other things) defines a
variant record type and an access type for referencing it.  Here is the
text of the errors generated for one of the lines:

-- Begin included text

 2693             if (comm_addr_group(i,j) /= NULL) then
..........................................1
%ADAC-E-NOTDECLOPOPND, (1) /= is not declared for the given operands [LRM 4.5]
%ADAC-I-SUPPLOPARGTYPE, (1) Result type of the first (or only) operand of /= is
        access type field_type_ptr in field_def at line 180
%ADAC-I-POSSUSECALL1, (1) Possibly a selected component of (or use clause for)
        package field_def in field_def at line 167 is intended; this would make
        implicit binary operator /= (field_type_ptr; field_type_ptr) returning
        BOOLEAN declared in field_def at line 180 visible for a legal call

-- End included text

I followed the implied suggestion of the (VAX/VMS) Ada compiler and inserted
a "use FIELD_DEF;" statement.  I know that with non-operator functions (i.e.:
functions who's names are alphanumeric + '_'), you can use the package name
to avoid 'use'.  As far as I know, there is no equivalent for operators.

Is this true?  If not, then how do I do it?

			Thanks in advance,
				-=:[ VAL ]:=-
--
|================== #include <disclaimer.h> ==================///=============|
| "AMIGA: The computer for the creative mind" (tm) Commodore /// Weber State  |
| "Macintosh: The computer for the rest of us"(tm) Apple \\\///   University  |
|== "I think, therefore I AMiga" -- val@csulx.weber.edu ==\///= Ogden UT USA =|



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How do I avoid 'use' in this case?
  1993-03-11 16:39 How do I avoid 'use' in this case? Val Kartchner
@ 1993-03-11 18:17 ` MILLS,JOHN M.
  1993-03-11 18:20 ` Erik Svensson FOA2
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: MILLS,JOHN M. @ 1993-03-11 18:17 UTC (permalink / raw)


In article <1993Mar11.163904.18135@fcom.cc.utah.edu> val@fcom.cc.utah.edu (Val Kartchner) writes:
>I know that the usage of 'use' is discouraged.  I generally agree, but I do
>not see a way around it in this case.  Is there something that I'm missing?

Val -- this is not an answer to your question, but a request for a little more
'context' [8*) on the original post.

I can understand the discouragement of 'use' for context clauses, though we
steered a middle ground in our group, trying to achieve readable source by
meaningful names and judicious 'use' context clauses.

We also have extensive memory-mapped, heterogeneous I/O to work with.  Is there
some alternative to 'use' in a representation clause?  Are the no-'use' 
switches in the editors smart enough to know the difference?

Thanks --jmm--

-- 
John M. Mills, SRE; Georgia Tech/GTRI/TSDL, Atlanta, GA 30332
uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!jm59
Internet: john.m.mills@gtri.gatech.edu
EBENE Chocolat Noir 72% de Cacao - WEISS - 42000 St.Etienne - very fine



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How do I avoid 'use' in this case?
  1993-03-11 16:39 How do I avoid 'use' in this case? Val Kartchner
  1993-03-11 18:17 ` MILLS,JOHN M.
@ 1993-03-11 18:20 ` Erik Svensson FOA2
  1993-03-16 13:12   ` Sandy Wise
  1993-03-18  3:02   ` Adam Beneschan
  1993-03-11 18:47 ` Arthur Evans
  1993-03-12 17:26 ` Gary Morris @ignite
  3 siblings, 2 replies; 8+ messages in thread
From: Erik Svensson FOA2 @ 1993-03-11 18:20 UTC (permalink / raw)


val@fcom.cc.utah.edu (Val Kartchner) writes:

>I know that the usage of 'use' is discouraged.  I generally agree, but I do
>not see a way around it in this case.  Is there something that I'm missing?

>We have a package called 'FIELD_DEF' which (among other things) defines a
>variant record type and an access type for referencing it.  Here is the
>text of the errors generated for one of the lines:

>-- Begin included text

> 2693             if (comm_addr_group(i,j) /= NULL) then
>..........................................1
>%ADAC-E-NOTDECLOPOPND, (1) /= is not declared for the given operands [LRM 4.5]
>%ADAC-I-SUPPLOPARGTYPE, (1) Result type of the first (or only) operand of /= is
>        access type field_type_ptr in field_def at line 180
>%ADAC-I-POSSUSECALL1, (1) Possibly a selected component of (or use clause for)
>        package field_def in field_def at line 167 is intended; this would make
>        implicit binary operator /= (field_type_ptr; field_type_ptr) returning
>        BOOLEAN declared in field_def at line 180 visible for a legal call

>-- End included text

>I followed the implied suggestion of the (VAX/VMS) Ada compiler and inserted
>a "use FIELD_DEF;" statement.  I know that with non-operator functions (i.e.:
>functions who's names are alphanumeric + '_'), you can use the package name
>to avoid 'use'.  As far as I know, there is no equivalent for operators.


Use rename instead.
Like this:

        function "/="(A,B:Foo) return boolean renames field_def."/=";

You could do field_def. "/="from the beginning, but that`s not so convinient.


HTH

cheers
--
     Erik Svensson
    Research Officer            National Defense Research Establishment (FOA)
 Guided Weapons Division        Stockholm, Sweden      eriks@fenix.lin.foa.se

"I like maxims that don't encourage behaviour modification." -- Calvin



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How do I avoid 'use' in this case?
  1993-03-11 16:39 How do I avoid 'use' in this case? Val Kartchner
  1993-03-11 18:17 ` MILLS,JOHN M.
  1993-03-11 18:20 ` Erik Svensson FOA2
@ 1993-03-11 18:47 ` Arthur Evans
  1993-03-12 17:26 ` Gary Morris @ignite
  3 siblings, 0 replies; 8+ messages in thread
From: Arthur Evans @ 1993-03-11 18:47 UTC (permalink / raw)
  Cc: Val Kartchner

val@fcom.cc.utah.edu (Val Kartchner) asks how, without a 'use' clause,
to get visibility to equality and other operators on objects of a type
declared in another package.

Suppose you have

    package DEFS is
	type X is ...
    end DEFS;

    -- ----------------------------

    with DEFS;
    procedure USER is
	P, Q: X;
    begin
	...
	if P = Q ...		// #1 ILLEGAL
	if DEFS."="(P, Q) ...	// #2 Qualification to get visibility

#1 is the problem you had.  #2 is a way to use dot qualification of an
operator.  It's perhaps a bit ugly, but it works and is convenient if
there are very few uses of the operator in package USER.

However, there's another way to go if there are lots of uses of the
operators.

    with DEFS;
    procedure USER is
	P, Q: X;
	function "="(Left, Right: in X) return boolean renames DEFS."=";
    begin
	...
	if P = Q ...		// Now legal

Art Evans
----------------------------------------------
Arthur Evans, Jr, PhD           Ada Consultant
461 Fairview Road
Pittsburgh PA  15238-1933
412-963-0839
ae@sei.cmu.edu



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How do I avoid 'use' in this case?
  1993-03-11 16:39 How do I avoid 'use' in this case? Val Kartchner
                   ` (2 preceding siblings ...)
  1993-03-11 18:47 ` Arthur Evans
@ 1993-03-12 17:26 ` Gary Morris @ignite
  3 siblings, 0 replies; 8+ messages in thread
From: Gary Morris @ignite @ 1993-03-12 17:26 UTC (permalink / raw)


In <1993Mar11.163904.18135@fcom.cc.utah.edu> val@fcom.cc.utah.edu (Val Kartchner) writes:
>We have a package called 'FIELD_DEF' which (among other things) defines a
>variant record type and an access type for referencing it.  Here is the
>text of the errors generated for one of the lines:

> 2693             if (comm_addr_group(i,j) /= NULL) then
>..........................................1
>%ADAC-E-NOTDECLOPOPND, (1) /= is not declared for the given operands [LRM 4.5]

>I know that with non-operator functions (i.e.:
>functions who's names are alphanumeric + '_'), you can use the package name
>to avoid 'use'.  As far as I know, there is no equivalent for operators.

This is not true, you can qualify operators with the package name.  We
mostly consider it not very readable so we use renames of the operator
instead. 

Either of these will work:
	
	if Field_Def."/="(comm_addr_group(i,j), NULL) then

Or add this rename in your package to allow your original code above to work,
this makes the "=" (and implicitly the "/=") operators visible (replace
Record_Type_Name with the actual name of the type):

    function "="(L,R: Field_Def.Record_Type_Name) return Boolean
      renames Field_Def."=";

        if comm_addr_group(i,j) /= NULL then

--GaryM
-- 
Gary Morris                      Internet: garym@telesoft.com
TeleUSE Development              UUCP:     uunet!telesoft!garym
Alsys Group (TeleSoft)           Phone:    +1 619-457-2700
San Diego, CA, USA               Fax:      +1 619-452-1334



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How do I avoid 'use' in this case?
  1993-03-11 18:20 ` Erik Svensson FOA2
@ 1993-03-16 13:12   ` Sandy Wise
  1993-03-18  3:02   ` Adam Beneschan
  1 sibling, 0 replies; 8+ messages in thread
From: Sandy Wise @ 1993-03-16 13:12 UTC (permalink / raw)


In article <1993Mar11.182021.1129@lin.foa.se> eriks@lin.foa.se (Erik Svensson FOA2) writes:
   Use rename instead.
   Like this:

           function "/="(A,B:Foo) return boolean renames field_def."/=";

Actually, use a rename like this:

           function "="(A,B:Foo) return boolean renames field_def."=";

One of those interesting little language lawyer level "features"  You
can't define not equal -- when you define equal you get not equal as
part of the deal...

I guess, there was concern that:

 'A /= B' might be different from 'not( A = B)'

        /s
--
Alexander Erskine Wise /\/\/\/\/\/\/\/\/\/\/\/\ Software Development Laboratory
/\/\/\/\/\/\/\/\/\/\/\/\/\/\ WISE@CS.UMASS.EDU /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\ This situation calls for large amounts of unadulterated CHOCOLATE! /\/\/\



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How do I avoid 'use' in this case?
  1993-03-11 18:20 ` Erik Svensson FOA2
  1993-03-16 13:12   ` Sandy Wise
@ 1993-03-18  3:02   ` Adam Beneschan
  1 sibling, 0 replies; 8+ messages in thread
From: Adam Beneschan @ 1993-03-18  3:02 UTC (permalink / raw)


In article <1993Mar11.182021.1129@lin.foa.se> eriks@lin.foa.se 
(Erik Svensson FOA2) writes:

>   Use rename instead.
>   Like this:
>
>           function "/="(A,B:Foo) return boolean renames field_def."/=";
>
>   You could do field_def. "/="from the beginning, but that`s not so 
>   convinient.

Wrong.  You cannot rename the "/=" operator.  What you need to do is
rename the "=" operator:

       function "="(A,B:Foo) return boolean renames field_def."=";

and then "/=" will be defined automatically.  /= is the only operator
that cannot be renamed explicitly.

By the way, the original post asked how to use operators such as /=
without using the USE clause.  Several responses have suggested
putting a RENAMES in the using package to make the operator visible.
While this is correct, if a common package P is with'ed by lots of
other packages Q1, Q2, etc., putting a RENAMES clause for every
operator in every using package Q1, Q2, ..., is quite tedious.
There's a better way around this, in my opinion.  Put the RENAMES in a
subpackage of P, like this:

    package P is

        type some_type_1 is record ... end record;
        type some_type_2 is (val1, val2, val3, ...);

        package OPERATORS is
            function "=" (left, right : some_type_1) return boolean
                renames P."=";
            function "=" (left, right : some_type_2) return boolean
                renames P."=";
            function "<" (left, right : some_type_2) return boolean
                renames P."<";
            function "<=" (left, right : some_type_2) return boolean
                renames P."<=";
            ... same for ">", ">="
        end OPERATORS;

    end P;

Now, in packages Q1, Q2, etc., you can make all the operators visible
very simply:

with P;
package Q1 is
    use P.OPERATORS;

    procedure PR (x, y : P.some_type_2) is
    begin
        if x = y then 
. . . . . . .


This does use the "use" statement, so if your Ada compiler has an
automatic preprocessor that deletes your source file if it sees the
word "use" :-), this solution won't work.  However, in environments
where rules like this aren't carved in stone, I think this is a great
solution.  Although it uses "use", it uses it in a restricted way that
doesn't make the whole world visible, and so IMHO it doesn't have the
problems that are usually associated with "use".

                                -- Adam



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How do I avoid 'use' in this case?
@ 1993-03-18 15:58 howland.reston.ans.net!zaphod.mps.ohio-state.edu!uwm.edu!caen!nic.umass.e
  0 siblings, 0 replies; 8+ messages in thread
From: howland.reston.ans.net!zaphod.mps.ohio-state.edu!uwm.edu!caen!nic.umass.e @ 1993-03-18 15:58 UTC (permalink / raw)


I (val@fcom.cc.utah.edu) wrote:
: I know that the usage of 'use' is discouraged.  I generally agree, but I do
: not see a way around it in this case.  Is there something that I'm missing?

Thanks to those of you who responded.  The solutions (posted and mailed) were
basically the same.  Here is the text that I used to solve it:

  function "="(LEFT,RIGHT:FIELD_DEF.FIELD_TYPE_PTR)
          return BOOLEAN
      rename FIELD_DEF."=";

I forgot that when referencing overloaded operators, you must quote them.

			Thanks again,
				-=:[ VAL ]:=-
--
|================== #include <disclaimer.h> ==================///=============|
| "AMIGA: The computer for the creative mind" (tm) Commodore /// Weber State  |
| "Macintosh: The computer for the rest of us"(tm) Apple \\\///   University  |
|== "I think, therefore I AMiga" -- val@csulx.weber.edu ==\///= Ogden UT USA =|

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1993-03-18 15:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-03-11 16:39 How do I avoid 'use' in this case? Val Kartchner
1993-03-11 18:17 ` MILLS,JOHN M.
1993-03-11 18:20 ` Erik Svensson FOA2
1993-03-16 13:12   ` Sandy Wise
1993-03-18  3:02   ` Adam Beneschan
1993-03-11 18:47 ` Arthur Evans
1993-03-12 17:26 ` Gary Morris @ignite
  -- strict thread matches above, loose matches on Subject: below --
1993-03-18 15:58 howland.reston.ans.net!zaphod.mps.ohio-state.edu!uwm.edu!caen!nic.umass.e

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