Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Newbie question: Binary operator expected?

1,588 views
Skip to first unread message

Geoffrey Laval

unread,
May 13, 2011, 12:05:53 PM5/13/11
to
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.

Adam Beneschan

unread,
May 13, 2011, 1:14:17 PM5/13/11
to

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

Ludovic Brenta

unread,
May 13, 2011, 1:50:24 PM5/13/11
to
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.

Geoffrey Laval

unread,
May 14, 2011, 6:40:30 AM5/14/11
to
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!
0 new messages