comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Vector (container) initialization: the schizophrenic ampersand
Date: Thu, 17 May 2012 16:33:48 -0700 (PDT)
Date: 2012-05-17T16:33:48-07:00	[thread overview]
Message-ID: <70510fa1-e554-44a7-9364-e745674c1bda@googlegroups.com> (raw)
In-Reply-To: <10616734.43.1337286031745.JavaMail.geo-discussion-forums@vbjy7>

On Thursday, May 17, 2012 1:20:31 PM UTC-7, marius63 wrote:
> Shouldn't this be the right idiom to initialize a vector (container) with literals:
> 
> use My_Vectors;
> V : My_Vectors.Vector := Element1 & Element2 & Element3;
> 
> Looks nice, but does not compile (with GNAT), because the compiler cannot make a decision on which "&" function to use where. Is there a way to give precedence to one of the "&" functions? Or some other nice solution? Thanks.
> 
> /*
> My current solution is to rename one of the functions:
> 
> use My_Vectors;
> 
> function "+" (L : My_Vectors.Vector; R : My_Element_Type)
>    renames My_Vectors."&";
> 
> V : My_Vectors.Vector := Element1 & Element2 + Element3;
> 
> Not elegant at all.
> */

It compiled for me the first time I tried it, so I think we need more information, in particular what your element type is.  A complete example that compiles except for that error would be helpful.

Parentheses won't help.  The operator precedence rules mean that the expression is always interpreted as (Element1 & Element2) & Element3 regardless of what functions the operators refer to.  

If your element type is some sort of array, then there could be a conflict with the built-in array concatenation operator.  The solution might be

   V : My_Vectors.Vector := My_Vectors.Vector'(Element1 & Element2) & Element3;

to make it clear that the first "&" must be the one that returns a Vector.

                           -- Adam



  parent reply	other threads:[~2012-05-17 23:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-17 20:20 Vector (container) initialization: the schizophrenic ampersand Marius Amado-Alves
2012-05-17 20:24 ` Jeffrey Carter
2012-05-17 20:26 ` Pascal Obry
2012-05-17 23:33 ` Adam Beneschan [this message]
2012-05-18  6:34   ` Marius Amado-Alves
2012-05-18  6:51   ` Marius Amado-Alves
2012-05-18 13:31     ` Robert A Duff
2012-05-18 18:55       ` Shark8
2012-05-18 22:44         ` Robert A Duff
2012-05-19  9:03       ` Marius Amado-Alves
2012-05-19 16:15         ` Robert A Duff
2012-05-21 16:02           ` Adam Beneschan
2012-05-21 17:04             ` Robert A Duff
2012-05-21 17:57               ` Adam Beneschan
2012-05-21 15:57         ` Adam Beneschan
2012-05-19  9:28     ` Dmitry A. Kazakov
replies disabled

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