comp.lang.ada
 help / color / mirror / Atom feed
* unconstrainded array question
@ 1998-09-19  0:00 Technobabble
  1998-09-19  0:00 ` Tom Moran
  1998-09-19  0:00 ` Tucker Taft
  0 siblings, 2 replies; 7+ messages in thread
From: Technobabble @ 1998-09-19  0:00 UTC (permalink / raw)


Greetings,

anyone know if it is legal or not in Ada95 to use a RANGE attribute on
an unconstrained array, as in the example:


package My_Package is

  procedure XYZ (This : in Object);

  type UC_Array is array (integer <>) of integer;
  xyz : AC_Array (1..100);


end My_Package;

then in the body ....
procedure XYZ (This : Object) is
begin

     for I in This.xyz'RANGE
         loop 
          ......
end XYZ;


Thanks,
Richmond




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

* Re: unconstrainded array question
  1998-09-19  0:00 unconstrainded array question Technobabble
@ 1998-09-19  0:00 ` Tom Moran
  1998-09-19  0:00   ` dewarr
                     ` (2 more replies)
  1998-09-19  0:00 ` Tucker Taft
  1 sibling, 3 replies; 7+ messages in thread
From: Tom Moran @ 1998-09-19  0:00 UTC (permalink / raw)


Since you gave no definition for whatever Object might be, it's a
little hard to tell what "This.xyz" might possibly be.  If xyz is an
array, then it clearly must have bounds and it's range is defined.  If
xyz is a type, and one with indefinite bounds, then obviously you
can't use those undefined bounds as if they had values. 




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

* Re: unconstrainded array question
  1998-09-19  0:00 ` Tom Moran
  1998-09-19  0:00   ` dewarr
@ 1998-09-19  0:00   ` Technobabble
  1998-09-19  0:00     ` dewarr
  1998-09-19  0:00   ` dewarr
  2 siblings, 1 reply; 7+ messages in thread
From: Technobabble @ 1998-09-19  0:00 UTC (permalink / raw)


In article <36033452.12702502@SantaClara01.news.InterNex.Net>,
tmoran@bix.com (Tom Moran) wrote:

> Since you gave no definition for whatever Object might be, it's a
> little hard to tell what "This.xyz" might possibly be.  If xyz is an
> array, then it clearly must have bounds and it's range is defined.  If
> xyz is a type, and one with indefinite bounds, then obviously you
> can't use those undefined bounds as if they had values. 

Greetings Tom,

xyz is an unconstrained array that is declared with a discriminant to
constrain it. Since it is of type unconstrained array I just want to know
if the RANGE attribute works eg. in a loop.  I guess that you are saying
YES it does since it does have bounds.  The question is if I have an
unconstrained array then I can declare many objects of that type with
different ranges, so will the RANGE attribute then return different ranges
for different objects.  Is this legal?
It makes sense to me that you are correct.  Also, Barnes is confusing on
the subject, page 125 of second edition, last paragraph on this topic.

Richmond




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

* Re: unconstrainded array question
  1998-09-19  0:00 unconstrainded array question Technobabble
  1998-09-19  0:00 ` Tom Moran
@ 1998-09-19  0:00 ` Tucker Taft
  1 sibling, 0 replies; 7+ messages in thread
From: Tucker Taft @ 1998-09-19  0:00 UTC (permalink / raw)


Technobabble (therionics@computer.org) wrote:

: Greetings,

: anyone know if it is legal or not in Ada95 to use a RANGE attribute on
: an unconstrained array, as in the example:

There is no such thing as an "unconstrained" array object.  There are
unconstrained array *subtypes*."  In the example below, the
"first subtype" UC_Array of the array type is unconstrained, but
the subtype of the object xyz is constrained to 1..100.

Extra care here in using terminology is important.

: package My_Package is

:   procedure XYZ (This : in Object);

:   type UC_Array is array (integer <>) of integer;
:   xyz : AC_Array (1..100);
    ^^^
This is illegal overloading by the way, since you can't have both
an overloadable declaration like the procedure XYZ and a non-overloadable
declaration like the array xyz in the same declarative region
(remember upper/lower case is irrelevant in Ada identifiers).

: end My_Package;

: then in the body ....
: procedure XYZ (This : Object) is
: begin

:      for I in This.xyz'RANGE

The 'Range attribute is allowed on *all* array objects, and on
all *constrained* array subtypes.  So UC_Array'Range would be
illegal, but <any_array_obj>'Range is allowed.

:          loop 
:           ......
: end XYZ;


: Thanks,
: Richmond

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company




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

* Re: unconstrainded array question
  1998-09-19  0:00 ` Tom Moran
  1998-09-19  0:00   ` dewarr
  1998-09-19  0:00   ` Technobabble
@ 1998-09-19  0:00   ` dewarr
  2 siblings, 0 replies; 7+ messages in thread
From: dewarr @ 1998-09-19  0:00 UTC (permalink / raw)


In article <36033452.12702502@SantaClara01.news.InterNex.Net>,
  tmoran@bix.com (Tom Moran) wrote:
> Since you gave no definition for whatever Object might be, it's a
> little hard to tell what "This.xyz" might possibly be.  If xyz is an
> array, then it clearly must have bounds and it's range is defined.  If
> xyz is a type, and one with indefinite bounds,
> then obviously you
> can't use those undefined bounds as if they had values.


As I often remind people, technical information that you
read on a newsgroup like this can be wrong or misleading.
This is an example.

There are no array objects in Ada with "indefinite" or
"undefined" bounds. All array objects are constrained and
have well defined bounds, so yes, of course, if the type
of Object is an array, you can use the 'Range attribute
in this case (it is indeed the primary and most familiar
use of the range attribute!)

The *type* of an array object may be unconstrained, but of
course, as in the original questioner's example, you apply
the Range attribute to the object, not the type!

Robert Dewar

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




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

* Re: unconstrainded array question
  1998-09-19  0:00 ` Tom Moran
@ 1998-09-19  0:00   ` dewarr
  1998-09-19  0:00   ` Technobabble
  1998-09-19  0:00   ` dewarr
  2 siblings, 0 replies; 7+ messages in thread
From: dewarr @ 1998-09-19  0:00 UTC (permalink / raw)


In article <36033452.12702502@SantaClara01.news.InterNex.Net>,
  tmoran@bix.com (Tom Moran) wrote:
> Since you gave no definition for whatever Object might be, it's a
> little hard to tell what "This.xyz" might possibly be.  If xyz is an
> array, then it clearly must have bounds and it's range is defined.  If
> xyz is a type, and one with indefinite bounds, then obviously you
> can't use those undefined bounds as if they had values.


Just to be a bit clearer on my response. I actually see how
Tom got confused, because the original question is indeed
itself a bit confused. But the point is that in the reference

This.xyz

we know that This is an object, so hence This.xyz is (if
legal at all) also an object, it is not possible that xyz is
a type in the example we are given (that's why Tom's response
is confusing).

Now it is true that the original example is confusing. It
is of course incomplete, and it can indeed be completed in
a correct manner, so it is not clearly wrong. However, the
best guess is that the person who posted the question is
indeed very confused (you can guess this from (a) the other
questions that the same person has asked, and (b) the odd
multiple use of the identifier xyz!)

It always amazes me how people write rather random stuff
instead of taking the effort to learn the syntax of the
language they want to write in precisely. It's like a
mathematician rummaging around trying to prove things
without first familiarizing themseles with the axioms
(and saying: well I looked at a couple of other proofs
in this area, and I have a reasonable feel for what the
axioms are likely to be :-)

>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




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

* Re: unconstrainded array question
  1998-09-19  0:00   ` Technobabble
@ 1998-09-19  0:00     ` dewarr
  0 siblings, 0 replies; 7+ messages in thread
From: dewarr @ 1998-09-19  0:00 UTC (permalink / raw)


In article <WishList-1809982157000001@a17.phoenix-14.goodnet.com>,
  WishList@2600.com (Technobabble) wrote:
> In article <36033452.12702502@SantaClara01.news.InterNex.Net>,
> tmoran@bix.com (Tom Moran) wrote:
>
> > Since you gave no definition for whatever Object might be, it's a
> > little hard to tell what "This.xyz" might possibly be.  If xyz is an
> > array, then it clearly must have bounds and it's range is defined.  If
> > xyz is a type, and one with indefinite bounds, then obviously you
> > can't use those undefined bounds as if they had values.
>
> Greetings Tom,
>
> xyz is an unconstrained array that is declared with a discriminant to
> constrain it. Since it is of type unconstrained array I just want to know
> if the RANGE attribute works eg. in a loop.  I guess that you are saying
> YES it does since it does have bounds.  The question is if I have an
> unconstrained array then I can declare many objects of that type with
> different ranges, so will the RANGE attribute then return different ranges
> for different objects.  Is this legal?
> It makes sense to me that you are correct.  Also, Barnes is confusing on
> the subject, page 125 of second edition, last paragraph on this topic.
>
> Richmond


I strongly suggest that you post COMPLETE examples. When you
are writing at a vague level and don't know the syntax of
the language precisely, let alone the semantics, it gets
VERY hard to guess what your misconceptions might be. You
will find that you get much better results if

(a) you write a complete program

(b) you compile it

(c) you try to figure out the error messages you get

(d) if you can't figure out the error messages, post the
ENTIRE (smallest possible) program that generates the
error messages, and ask.

I often find that students think they know something and so
they pose a question in a garbled form, that depends on this
knowledge, the only trouble is, the knowledge happens to be
wrong.

If you don't post a complete example, you may easily have
the phenomenon of people being confused by what you write,
and then adding to the confusion by answering something
different than what you thought you were asking.


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




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

end of thread, other threads:[~1998-09-19  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-19  0:00 unconstrainded array question Technobabble
1998-09-19  0:00 ` Tom Moran
1998-09-19  0:00   ` dewarr
1998-09-19  0:00   ` Technobabble
1998-09-19  0:00     ` dewarr
1998-09-19  0:00   ` dewarr
1998-09-19  0:00 ` Tucker Taft

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