comp.lang.ada
 help / color / mirror / Atom feed
* question on using `with` without  `use` and visibility of operators such as '*'
@ 2012-07-30  6:04 Nasser M. Abbasi
  2012-07-30  6:30 ` Niklas Holsti
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nasser M. Abbasi @ 2012-07-30  6:04 UTC (permalink / raw)


<warning, newbie in Ada>

I prefer to use the long name of a package when I call some of its
functions. So I like to write

------------------------
with package_foo;
    package_foo.function_name();
-----------------------

rather than

-----------------------
with package_foo; use package_foo;
   function_name();
----------------------

So that when reading the code, I know where things are.

This worked well so far, but when the package happened to export
functions/operators  such as '*' or "+" for the types, then it will
not work any more. i.e. I really want to just write

            x * y

where x,y are variables with types defined in the package, and not write

            x package_foo("*") y

(or whatever the correct syntax would be)

This is annoying. It means I have now to `use package_foo`
to be able to write  x*y, since "*" is defined in the package.

Is there a way around this, so I can avoid using `use` but still
be able to just write   x * y  (may be use something like
`use package_foo("*") at the top if this possible)

I can provide example if needed. The error I get are of the form

       there is no applicable operator "*" for type .....

This error goes away when I add `use package_foo`

(Ada is so picky !)

thanks,
--Nasser



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

* Re: question on using `with` without  `use` and visibility of operators such as '*'
  2012-07-30  6:04 question on using `with` without `use` and visibility of operators such as '*' Nasser M. Abbasi
@ 2012-07-30  6:30 ` Niklas Holsti
  2012-07-30  6:33 ` Dmitry A. Kazakov
  2012-07-30  6:50 ` Ludovic Brenta
  2 siblings, 0 replies; 4+ messages in thread
From: Niklas Holsti @ 2012-07-30  6:30 UTC (permalink / raw)


On 12-07-30 09:04 , Nasser M. Abbasi wrote:
> <warning, newbie in Ada>
> 
> I prefer to use the long name of a package when I call some of its
> functions. So I like to write
> 
> ------------------------
> with package_foo;
>    package_foo.function_name();
> -----------------------
> 
> rather than
> 
> -----------------------
> with package_foo; use package_foo;
>   function_name();
> ----------------------
> 
> So that when reading the code, I know where things are.
> 
> This worked well so far, but when the package happened to export
> functions/operators  such as '*' or "+" for the types, then it will
> not work any more. i.e. I really want to just write
> 
>            x * y
> 
> where x,y are variables with types defined in the package, and not write
> 
>            x package_foo("*") y
> 
> (or whatever the correct syntax would be)
> 
> This is annoying. It means I have now to `use package_foo`
> to be able to write  x*y, since "*" is defined in the package.
> 
> Is there a way around this, so I can avoid using `use` but still
> be able to just write   x * y  (may be use something like
> `use package_foo("*") at the top if this possible)

Use "use type package_foo.T", where T is the type of x and y. Then you
can apply the "primitive operators" of the type with qualifying with the
package name.

See the "use_type_clause" in
http://www.ada-auth.org/standards/12rm/html/RM-8-4.html.

Note the additional names made visible when the "all" keyword is placed
between "use" and "type".

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .



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

* Re: question on using `with` without  `use` and visibility of operators such as '*'
  2012-07-30  6:04 question on using `with` without `use` and visibility of operators such as '*' Nasser M. Abbasi
  2012-07-30  6:30 ` Niklas Holsti
@ 2012-07-30  6:33 ` Dmitry A. Kazakov
  2012-07-30  6:50 ` Ludovic Brenta
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry A. Kazakov @ 2012-07-30  6:33 UTC (permalink / raw)


On Mon, 30 Jul 2012 01:04:34 -0500, Nasser M. Abbasi wrote:

> I prefer to use the long name of a package when I call some of its
> functions.

[...]

> i.e. I really want to just write
> 
>             x * y

Which is in a clear contradiction to what you stated first. "*" is a name
of a function.

> where x,y are variables with types defined in the package, and not write
>
>            x package_foo("*") y

   Package_Foo."*" (X, Y)
 
> This is annoying.

There is a restricted form of use which brings up only operations of a
type:

   use type Package_Foo.Float_Type;
   X, Y : Package_Foo.Float_Type;
begin
   ... X * Y ... -- This is OK now

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: question on using `with` without  `use` and visibility of operators such as '*'
  2012-07-30  6:04 question on using `with` without `use` and visibility of operators such as '*' Nasser M. Abbasi
  2012-07-30  6:30 ` Niklas Holsti
  2012-07-30  6:33 ` Dmitry A. Kazakov
@ 2012-07-30  6:50 ` Ludovic Brenta
  2 siblings, 0 replies; 4+ messages in thread
From: Ludovic Brenta @ 2012-07-30  6:50 UTC (permalink / raw)


Nasser M. Abbasi writes on comp.lang.ada:
> This is annoying. It means I have now to `use package_foo` to be able
> to write x*y, since "*" is defined in the package.
>
> Is there a way around this, so I can avoid using `use` but still be
> able to just write x * y (may be use something like `use
> package_foo("*") at the top if this possible)

package P is
   type T is private;
   function "*" (Left, Right : in T) return T;
end P;

wth P;
procedure Proc is
   Foo, Bar : P.T;
   use type P.T; -- <-- watch this!
   Baz : constant P.T := Foo * Bar; -- P."*" is now directly visible
begin
   null;
end Proc;

-- 
Ludovic Brenta.



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

end of thread, other threads:[~2012-08-07 12:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-30  6:04 question on using `with` without `use` and visibility of operators such as '*' Nasser M. Abbasi
2012-07-30  6:30 ` Niklas Holsti
2012-07-30  6:33 ` Dmitry A. Kazakov
2012-07-30  6:50 ` Ludovic Brenta

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