* How to include vector operators?
@ 2010-12-06 21:03 tolkamp
2010-12-06 21:37 ` Adam Beneschan
2010-12-07 2:53 ` Gautier write-only
0 siblings, 2 replies; 4+ messages in thread
From: tolkamp @ 2010-12-06 21:03 UTC (permalink / raw)
In my application the package Ada.Numerics.Generic_Real_Arrays is
included.
Code:
with Ada.Numerics.Generic_Real_Arrays;
package Vectors is new Ada.Numerics.Generic_Real_Arrays(Float);
How to include the vector operators like "+" and "-" ?
I tried the follwing:
function "+" (Left, Right : Vectors.Real_Vector) return
Vectors.Real_Vector
renames
Ada.Numerics.Generic_Real_Arrays.Instantiations."+";
However this gives the error:
invalid prefix in selected component "Generic_Real_Arrays".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to include vector operators?
2010-12-06 21:03 How to include vector operators? tolkamp
@ 2010-12-06 21:37 ` Adam Beneschan
2010-12-07 11:11 ` tolkamp
2010-12-07 2:53 ` Gautier write-only
1 sibling, 1 reply; 4+ messages in thread
From: Adam Beneschan @ 2010-12-06 21:37 UTC (permalink / raw)
On Dec 6, 1:03 pm, tolkamp <f.tolk...@gmail.com> wrote:
> In my application the package Ada.Numerics.Generic_Real_Arrays is
> included.
>
> Code:
>
> with Ada.Numerics.Generic_Real_Arrays;
> package Vectors is new Ada.Numerics.Generic_Real_Arrays(Float);
>
> How to include the vector operators like "+" and "-" ?
>
> I tried the follwing:
> function "+" (Left, Right : Vectors.Real_Vector) return
> Vectors.Real_Vector
> renames
> Ada.Numerics.Generic_Real_Arrays.Instantiations."+";
>
> However this gives the error:
> invalid prefix in selected component "Generic_Real_Arrays".
function "+" (Left, Right : Vectors.Real_Vector) return
Vectors.Real_Vector
renames Vectors."+";
But you probably really want to use this, which will make all the
operators visible:
use type Vectors.Real_Vector;
(and maybe the same for Real_Matrix).
But NOT this:
use type Ada.Numerics.Generic_Real_Arrays.Real_Vector;
You can't access declarations in a generic package directly. You have
to access the declarations in a generic *instance*.
-- Adam
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to include vector operators?
2010-12-06 21:03 How to include vector operators? tolkamp
2010-12-06 21:37 ` Adam Beneschan
@ 2010-12-07 2:53 ` Gautier write-only
1 sibling, 0 replies; 4+ messages in thread
From: Gautier write-only @ 2010-12-07 2:53 UTC (permalink / raw)
> with Ada.Numerics.Generic_Real_Arrays;
Since it's generic, you can't use it directly. It's why you have:
> package Vectors is new Ada.Numerics.Generic_Real_Arrays(Float);
>
> How to include the vector operators like "+" and "-" ?
I guess you want to write things like (i):
u+v
whereas now you need to write (ii)
Vectors."+"(u,v)
To be able to write the form (i), you can put
use Vectors;
after the above definition (package Vectors is new ...)
and you'll be happy.
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/
NB: follow the above link for a working e-mail address
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to include vector operators?
2010-12-06 21:37 ` Adam Beneschan
@ 2010-12-07 11:11 ` tolkamp
0 siblings, 0 replies; 4+ messages in thread
From: tolkamp @ 2010-12-07 11:11 UTC (permalink / raw)
On 6 dec, 22:37, Adam Beneschan <a...@irvine.com> wrote:
> On Dec 6, 1:03 pm, tolkamp <f.tolk...@gmail.com> wrote:
>
>
>
>
>
> > In my application the package Ada.Numerics.Generic_Real_Arrays is
> > included.
>
> > Code:
>
> > with Ada.Numerics.Generic_Real_Arrays;
> > package Vectors is new Ada.Numerics.Generic_Real_Arrays(Float);
>
> > How to include the vector operators like "+" and "-" ?
>
> > I tried the follwing:
> > function "+" (Left, Right : Vectors.Real_Vector) return
> > Vectors.Real_Vector
> > renames
> > Ada.Numerics.Generic_Real_Arrays.Instantiations."+";
>
> > However this gives the error:
> > invalid prefix in selected component "Generic_Real_Arrays".
>
> function "+" (Left, Right : Vectors.Real_Vector) return
> Vectors.Real_Vector
> renames Vectors."+";
>
> But you probably really want to use this, which will make all the
> operators visible:
>
> use type Vectors.Real_Vector;
>
> (and maybe the same for Real_Matrix).
>
> But NOT this:
>
> use type Ada.Numerics.Generic_Real_Arrays.Real_Vector;
>
> You can't access declarations in a generic package directly. You have
> to access the declarations in a generic *instance*.
>
> -- Adam- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
Thank you for your solution. Now it works correct.
Fred
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-12-07 11:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-06 21:03 How to include vector operators? tolkamp
2010-12-06 21:37 ` Adam Beneschan
2010-12-07 11:11 ` tolkamp
2010-12-07 2:53 ` Gautier write-only
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox