comp.lang.ada
 help / color / mirror / Atom feed
* Newbie question: Binary operator expected?
@ 2011-05-13 16:05 Geoffrey Laval
  2011-05-13 17:14 ` Adam Beneschan
  2011-05-13 17:50 ` Ludovic Brenta
  0 siblings, 2 replies; 4+ messages in thread
From: Geoffrey Laval @ 2011-05-13 16:05 UTC (permalink / raw)


Hi everybody,
I'm fairly new to Ada and I've tried different ways, even switching
from Bounded_Strings to standard strings, I don't know what I do
wrong!

eightball.adb:8:60: binary operator expected

Here is my source code:

  5 procedure eightball is
  6         rep : integer range 1 .. 3;
  7         touche : character;
  8         package BS_Length is new
Generic_Bounded_Length(300'Length);
  9         use BS_Length;
 10         question : bounded_string;
 11         question : To_Bounded_String;
 12         subtype reponse is integer range 1 .. 3;
 13         package reponseAlea is new
Ada.Numerics.Discrete_Random(reponse);
 14         use reponseAlea;
 15         G : Generator;
 16 begin

I've changed it several times, and the error is still around the
length attribute. I think in the course of changing it, I even
worsened the wrongness of the code. I'm also confused as I've stumbled
upon different websites and everybody seems to have its own manner to
use strings. Some use these like I did and others do Sname :
bounded_string := "something"; so what is the right way?
I've tried to find out where I was wrong by searching about binary
operators, but it didn't worked out, so I thought I'd progress easier
on this if I asked here even if most questions asked are one level or
a thousand higher than mine. Also, the compiler I'm using is Gnat.
(Gnat is the compiler, right, and GPS the IDE?)
Thanks in advance,
Geoffrey Laval.



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

* Re: Newbie question: Binary operator expected?
  2011-05-13 16:05 Newbie question: Binary operator expected? Geoffrey Laval
@ 2011-05-13 17:14 ` Adam Beneschan
  2011-05-13 17:50 ` Ludovic Brenta
  1 sibling, 0 replies; 4+ messages in thread
From: Adam Beneschan @ 2011-05-13 17:14 UTC (permalink / raw)


On May 13, 9:05 am, Geoffrey Laval <geolava1...@gmail.com> wrote:
> Hi everybody,
> I'm fairly new to Ada and I've tried different ways, even switching
> from Bounded_Strings to standard strings, I don't know what I do
> wrong!
>
> eightball.adb:8:60: binary operator expected
>
> Here is my source code:
>
>   5 procedure eightball is
>   6         rep : integer range 1 .. 3;
>   7         touche : character;
>   8         package BS_Length is new
> Generic_Bounded_Length(300'Length);
>   9         use BS_Length;
>  10         question : bounded_string;
>  11         question : To_Bounded_String;
>  12         subtype reponse is integer range 1 .. 3;
>  13         package reponseAlea is new
> Ada.Numerics.Discrete_Random(reponse);
>  14         use reponseAlea;
>  15         G : Generator;
>  16 begin
>
> I've changed it several times, and the error is still around the
> length attribute. I think in the course of changing it, I even
> worsened the wrongness of the code. I'm also confused as I've stumbled
> upon different websites and everybody seems to have its own manner to
> use strings. Some use these like I did and others do Sname :
> bounded_string := "something"; so what is the right way?
> I've tried to find out where I was wrong by searching about binary
> operators, but it didn't worked out, so I thought I'd progress easier
> on this if I asked here even if most questions asked are one level or
> a thousand higher than mine. Also, the compiler I'm using is Gnat.
> (Gnat is the compiler, right, and GPS the IDE?)
> Thanks in advance,
> Geoffrey Laval.

300'Length is not Ada syntax.  'Length is an attribute that you can
apply to an *array* or an *array type* to get its length.  If A is a
one-dimensional array, A'Length is its length.  But 300 isn't an
array, it's a number.  If you want to specify *that* the length of
something is 300, this isn't the right syntax for that.

Generic_Bounded_Length(Max => 300) or just Generic_Bounded_Length(300)
will work.

If, on the other hand, you wanted to indicate the length of the
*movie* 300, the Ada language can't be expected to know that.  (It's
117 minutes.  I looked it up.)

                                -- Adam



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

* Re: Newbie question: Binary operator expected?
  2011-05-13 16:05 Newbie question: Binary operator expected? Geoffrey Laval
  2011-05-13 17:14 ` Adam Beneschan
@ 2011-05-13 17:50 ` Ludovic Brenta
  2011-05-14 10:40   ` Geoffrey Laval
  1 sibling, 1 reply; 4+ messages in thread
From: Ludovic Brenta @ 2011-05-13 17:50 UTC (permalink / raw)


Geoffrey Laval writes:
> Hi everybody,
> I'm fairly new to Ada [...]

Welcome!

> (Gnat is the compiler, right, and GPS the IDE?)

Yes and yes.

Adam already answered your other questions.

Personally, I think it is a bad idea to mix French identifiers with
English keywords.  Even though I am French, the effort required to
switch languages on the fly distracts me from understanding of the
program text.  With experience you will probably end up thinking the
same.

-- 
Ludovic Brenta.



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

* Re: Newbie question: Binary operator expected?
  2011-05-13 17:50 ` Ludovic Brenta
@ 2011-05-14 10:40   ` Geoffrey Laval
  0 siblings, 0 replies; 4+ messages in thread
From: Geoffrey Laval @ 2011-05-14 10:40 UTC (permalink / raw)


Hi,
Thanks to Adam Benescham, it works now!
I'll take Ludovic Brenta's advice into account. Even if these are tiny
programs written just to learn, I notice after reading it that I often
took a little time to think of the french word when writing these.
Thanks a lot to you both!



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

end of thread, other threads:[~2011-05-14 10:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-13 16:05 Newbie question: Binary operator expected? Geoffrey Laval
2011-05-13 17:14 ` Adam Beneschan
2011-05-13 17:50 ` Ludovic Brenta
2011-05-14 10:40   ` Geoffrey Laval

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