comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Understanding generic package functions
Date: Tue, 3 Nov 2015 10:27:45 -0700
Date: 2015-11-03T10:27:45-07:00	[thread overview]
Message-ID: <n1aqmc$7bv$2@dont-email.me> (raw)
In-Reply-To: <6a1eb518-801f-4a1d-af55-e122c2570b12@googlegroups.com>

On 11/03/2015 12:59 AM, Nick Gordon wrote:
> 
> Oh! I see! Suddenly this makes much more sense. I appreciate this a lot! I
> see that it wasn't the declaration of Ada.Numerics.e that was the issue, but
> the generic package. How though do I use the overridden binary operator ** in
> that case? Do I call X MyPack."**" Y or is there some way for me to inform
> the compiler do it, like use MyPack;?

You have a number of options.

1. Full dotted name. An operator is a function just like any other function, and
can be called just like any other function:

Math."**" (X, Y)

2. Renaming.

function "**" (Left : Float; Right : Float) return Float renames Math."**";

This lets you use "**" as an infix operator: X ** Y

3. A use clause.

use Math;

This also lets you use "**" as an infix operator: X ** Y

The use clause gives you direct visibility to everything in the public part of
the pkg spec. Sometimes that's not desirable. I tend to avoid use clauses, since
they often make code harder to understand. I won't object too much for pkgs in
the standard library or for a limited scope with lots of references.

Not applicable in this case, but when a package declares a type and operations
on the type, you can use a "use type" clause

use [all] type Package_Name.Type_Name;

This gives direct visibility to the operators for Type_Name but not for anything
else in the pkg. If "all" is included, it makes some other things directly
visible, too, of which enumeration literals are the most commonly used.

-- 
Jeff Carter
"Drown in a vat of whiskey. Death, where is thy sting?"
Never Give a Sucker an Even Break
106

  parent reply	other threads:[~2015-11-03 17:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-03  0:45 Understanding generic package functions Nick Gordon
2015-11-03  3:36 ` Jeffrey R. Carter
2015-11-03  6:59 ` Randy Brukardt
2015-11-03  7:59   ` Nick Gordon
2015-11-03  9:15     ` briot.emmanuel
2015-11-03 17:27     ` Jeffrey R. Carter [this message]
2015-11-03  9:40 ` Stephen Leake
replies disabled

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