comp.lang.ada
 help / color / mirror / Atom feed
* Stream_Element_Array and an empty array
@ 2001-08-22 13:34 
  2001-08-22 13:42 ` Samuel Tardieu
  2001-08-22 14:22 ` Samuel T. Harris
  0 siblings, 2 replies; 13+ messages in thread
From:  @ 2001-08-22 13:34 UTC (permalink / raw)


Hello

I would like to sth like this:

A : Stream_Elemet_Array;
A := <empty array>;

I dont know how to write empty array that A'Length = 0.
Does anybody know?

Godfryd

-- 
|  Michal Nowikowski <godfryd@zamek.gda.pl>
|  Registered Linux User #165183            
|  http://www.glc.zamek.gda.pl/



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

* Re: Stream_Element_Array and an empty array
  2001-08-22 13:34 Stream_Element_Array and an empty array 
@ 2001-08-22 13:42 ` Samuel Tardieu
  2001-08-22 13:56   ` Reivilo Snuved
  2001-08-22 14:54   ` Ted Dennison
  2001-08-22 14:22 ` Samuel T. Harris
  1 sibling, 2 replies; 13+ messages in thread
From: Samuel Tardieu @ 2001-08-22 13:42 UTC (permalink / raw)
  To: comp.lang.ada

On 22/08, =?ISO-8859-2?q?=22Micha=B3=@ada.eu.org wrote:
| Hello
| 
| I would like to sth like this:
| 
| A : Stream_Elemet_Array;
| A := <empty array>;
| 
| I dont know how to write empty array that A'Length = 0.
| Does anybody know?

Like for any array:

  A : Ada.Streams.Stream_Element_Array (0 .. -1);

A'Length being defined as A'Last - A'First + 1, you will get a zero length.

  Sam
-- 
  Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam




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

* Re: Stream_Element_Array and an empty array
  2001-08-22 13:42 ` Samuel Tardieu
@ 2001-08-22 13:56   ` Reivilo Snuved
  2001-08-22 14:19     ` 
  2001-08-22 14:54   ` Ted Dennison
  1 sibling, 1 reply; 13+ messages in thread
From: Reivilo Snuved @ 2001-08-22 13:56 UTC (permalink / raw)


Samuel Tardieu <sam@rfc1149.net> writes:

> Like for any array:
> 
>   A : Ada.Streams.Stream_Element_Array (0 .. -1);
> 
> A'Length being defined as A'Last - A'First + 1, you will get a zero length.
> 

A (1 .. 0) is my favourite idiom.




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

* Re: Stream_Element_Array and an empty array
  2001-08-22 13:56   ` Reivilo Snuved
@ 2001-08-22 14:19     ` 
  2001-08-22 14:25       ` 
                         ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From:  @ 2001-08-22 14:19 UTC (permalink / raw)


W artykule <stk7zw2o60.fsf@aonix.fr>, "Reivilo Snuved"
<odevuns@iname.junk.com> napisaďż˝(a):

> Samuel Tardieu <sam@rfc1149.net> writes:
> 
>>   A : Ada.Streams.Stream_Element_Array (0 .. -1);
>> 
>> A'Length being defined as A'Last - A'First + 1, you will get a zero
>> length.

ok, but it is variable A array which length is 0;
i want to substitute a value;

when you have array A with length=5, you do:
A := (1, 2, 3, 4, 5);

what to do when A's length is 0
A := (); -- doesnt work

-- 
|  Michal Nowikowski <godfryd@zamek.gda.pl>
|  Registered Linux User #165183            
|  http://www.glc.zamek.gda.pl/



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

* Re: Stream_Element_Array and an empty array
  2001-08-22 13:34 Stream_Element_Array and an empty array 
  2001-08-22 13:42 ` Samuel Tardieu
@ 2001-08-22 14:22 ` Samuel T. Harris
  2001-08-23  8:37   ` Philip Anderson
  1 sibling, 1 reply; 13+ messages in thread
From: Samuel T. Harris @ 2001-08-22 14:22 UTC (permalink / raw)


""Micha³owikowski\" \"" wrote:
> 
> Hello
> 
> I would like to sth like this:
> 
> A : Stream_Elemet_Array;
> A := <empty array>;
> 
> I dont know how to write empty array that A'Length = 0.
> Does anybody know?
> 
> Godfryd
> 

As others have shown, ...

a : stream_element_array (1..0);

... is the appropriate declaration.
However, you have included an assignment
to A and appear to want to know what
expression will yield such an array.

Given that in the above text A is a variable,
no assignment is necesary. If you must have
an assignment, or an initial expression
because it is constant, then you can
do the following ...

nil : constant stream_element_array (1..0) := (others => 0);
...
a := nil;

-- 
Samuel T. Harris, Senior Software Engineer II
Raytheon, Aerospace Engineering Services
"If you can make it, We can fake it!"



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

* Re: Stream_Element_Array and an empty array
  2001-08-22 14:19     ` 
@ 2001-08-22 14:25       ` 
  2001-08-22 14:28         ` Florian Weimer
  2001-08-22 14:28       ` David C. Hoos
  2001-08-22 15:13       ` Claude SIMON
  2 siblings, 1 reply; 13+ messages in thread
From:  @ 2001-08-22 14:25 UTC (permalink / raw)


W artykule <pan.2001.08.22.16.19.49.568.13195@zamek.gda.pl>,
"=?ISO-8859-2?q?=22Micha=B3= Nowikowski" <godfryd@zamek.gda.pl>
napisaďż˝(a):

> 
> ok, but it is variable A array which length is 0; i want to substitute a
> value;
> 
> when you have array A with length=5, you do: A := (1, 2, 3, 4, 5);
> 
> what to do when A's length is 0
> A := (); -- doesnt work

in other words: when i've got procedure

procedure P (A : Stream_Element_Array);

and i want to put 0-long array as an argument


-- 
|  Michal Nowikowski <godfryd@zamek.gda.pl>
|  Registered Linux User #165183            
|  http://www.glc.zamek.gda.pl/



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

* Re: Stream_Element_Array and an empty array
  2001-08-22 14:19     ` 
  2001-08-22 14:25       ` 
@ 2001-08-22 14:28       ` David C. Hoos
  2001-08-22 15:13       ` Claude SIMON
  2 siblings, 0 replies; 13+ messages in thread
From: David C. Hoos @ 2001-08-22 14:28 UTC (permalink / raw)
  To: comp.lang.ada

You do

A := (1 .. 0 => <any-value>);

The value of <any-value> is immaterial because you're
assigning zero elements of that value.

----- Original Message -----
From: <=?ISO-8859-2?q?=22Micha=B3=@ada.eu.org>; <Nowikowski@ada.eu.org>; <"
<godfryd@zamek.gda.pl>"@ada.eu.org>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Wednesday, August 22, 2001 9:19 AM
Subject: Re: Stream_Element_Array and an empty array


> W artykule <stk7zw2o60.fsf@aonix.fr>, "Reivilo Snuved"
> <odevuns@iname.junk.com> napisaďż˝(a):
>
> > Samuel Tardieu <sam@rfc1149.net> writes:
> >
> >>   A : Ada.Streams.Stream_Element_Array (0 .. -1);
> >>
> >> A'Length being defined as A'Last - A'First + 1, you will get a zero
> >> length.
>
> ok, but it is variable A array which length is 0;
> i want to substitute a value;
>
> when you have array A with length=5, you do:
> A := (1, 2, 3, 4, 5);
>
> what to do when A's length is 0
> A := (); -- doesnt work
>
> --
> |  Michal Nowikowski <godfryd@zamek.gda.pl>
> |  Registered Linux User #165183
> |  http://www.glc.zamek.gda.pl/
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>




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

* Re: Stream_Element_Array and an empty array
  2001-08-22 14:25       ` 
@ 2001-08-22 14:28         ` Florian Weimer
  2001-08-22 14:37           ` 
  0 siblings, 1 reply; 13+ messages in thread
From: Florian Weimer @ 2001-08-22 14:28 UTC (permalink / raw)


=?ISO-8859-2?q?=22Micha=B3= Nowikowski" <godfryd@zamek.gda.pl> writes:

> in other words: when i've got procedure
> 
> procedure P (A : Stream_Element_Array);
> 
> and i want to put 0-long array as an argument

P (((1 .. 0) => 0));

Not very pretty, but it works.



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

* Re: Stream_Element_Array and an empty array
  2001-08-22 14:28         ` Florian Weimer
@ 2001-08-22 14:37           ` 
  0 siblings, 0 replies; 13+ messages in thread
From:  @ 2001-08-22 14:37 UTC (permalink / raw)


W artykule <tgu1z0qicc.fsf@mercury.rus.uni-stuttgart.de>, "Florian Weimer"
<Florian.Weimer@rus.uni-stuttgart.de> napisaďż˝(a):

> 
>> in other words: when i've got procedure
>> 
>> procedure P (A : Stream_Element_Array);
>> 
>> and i want to put 0-long array as an argument
> 
> P (((1 .. 0) => 0));
> 
> Not very pretty, but it works.

yes it wors
thanks to all that have answered

-- 
|  Michal Nowikowski <godfryd@zamek.gda.pl>
|  Registered Linux User #165183            
|  http://www.glc.zamek.gda.pl/



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

* Re: Stream_Element_Array and an empty array
  2001-08-22 13:42 ` Samuel Tardieu
  2001-08-22 13:56   ` Reivilo Snuved
@ 2001-08-22 14:54   ` Ted Dennison
  1 sibling, 0 replies; 13+ messages in thread
From: Ted Dennison @ 2001-08-22 14:54 UTC (permalink / raw)


In article <mailman.998487810.2223.comp.lang.ada@ada.eu.org>, Samuel Tardieu
says...
>
>On 22/08, =?ISO-8859-2?q?=22Micha=B3=@ada.eu.org wrote:
>| Hello
>| 
>| I would like to sth like this:
>| 
>| A : Stream_Elemet_Array;
>| A := <empty array>;
>| 
>| I dont know how to write empty array that A'Length = 0.
>| Does anybody know?
>
>Like for any array:
>
>  A : Ada.Streams.Stream_Element_Array (0 .. -1);

Keey your eyes open when using this though. I found at least one compiler (*not*
Gnat) that doesn't like to perform stream ops on 0 length arrays. That's a bug,
but it happened...

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: Stream_Element_Array and an empty array
  2001-08-22 14:19     ` 
  2001-08-22 14:25       ` 
  2001-08-22 14:28       ` David C. Hoos
@ 2001-08-22 15:13       ` Claude SIMON
  2 siblings, 0 replies; 13+ messages in thread
From: Claude SIMON @ 2001-08-22 15:13 UTC (permalink / raw)




""Micha�owikowski\" \"" a �crit :

> W artykule <stk7zw2o60.fsf@aonix.fr>, "Reivilo Snuved"
> <odevuns@iname.junk.com> napisa�(a):
>
> > Samuel Tardieu <sam@rfc1149.net> writes:
> >
> >>   A : Ada.Streams.Stream_Element_Array (0 .. -1);
> >>
> >> A'Length being defined as A'Last - A'First + 1, you will get a zero
> >> length.
>
> ok, but it is variable A array which length is 0;
> i want to substitute a value;
>
> when you have array A with length=5, you do:
> A := (1, 2, 3, 4, 5);
>
> what to do when A's length is 0
> A := (); -- doesnt work
>

You do nothing, that is : you put no element in A :-)

or if you want to do something :
A := (1 .. 0 => ...);


>
> --
> |  Michal Nowikowski <godfryd@zamek.gda.pl>
> |  Registered Linux User #165183
> |  http://www.glc.zamek.gda.pl/




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

* Re: Stream_Element_Array and an empty array
  2001-08-22 14:22 ` Samuel T. Harris
@ 2001-08-23  8:37   ` Philip Anderson
  2001-08-23 14:02     ` Samuel T. Harris
  0 siblings, 1 reply; 13+ messages in thread
From: Philip Anderson @ 2001-08-23  8:37 UTC (permalink / raw)


"Samuel T. Harris" wrote:
> 
<snip>
> Given that in the above text A is a variable,
> no assignment is necesary. If you must have
> an assignment, or an initial expression
> because it is constant, then you can
> do the following ...
> 
> nil : constant stream_element_array (1..0) := (others => 0);
> ...
> a := nil;

That must the clearest Ada way of obtaining a zero-length array of a
particular type; declare an example and give it a suitable name (Nil,
Empty_Array, Zero_Length_Array, whatever), since the result of this
particular Ada idiom is easier to understand given this clue.  It then
becomes obvious what you are doing when you pass it as a parameter.


-- 
hwyl/cheers,
Philip Anderson
Alenia Marconi Systems
Cwmbr�n, Cymru/Wales



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

* Re: Stream_Element_Array and an empty array
  2001-08-23  8:37   ` Philip Anderson
@ 2001-08-23 14:02     ` Samuel T. Harris
  0 siblings, 0 replies; 13+ messages in thread
From: Samuel T. Harris @ 2001-08-23 14:02 UTC (permalink / raw)


Philip Anderson wrote:
> 
> "Samuel T. Harris" wrote:
> >
> <snip>
> > Given that in the above text A is a variable,
> > no assignment is necesary. If you must have
> > an assignment, or an initial expression
> > because it is constant, then you can
> > do the following ...
> >
> > nil : constant stream_element_array (1..0) := (others => 0);
> > ...
> > a := nil;
> 
> That must the clearest Ada way of obtaining a zero-length array of a
> particular type; declare an example and give it a suitable name (Nil,
> Empty_Array, Zero_Length_Array, whatever), since the result of this
> particular Ada idiom is easier to understand given this clue.  It then
> becomes obvious what you are doing when you pass it as a parameter.
> 

Thanks for that.

For years (decades) I have made is a habit to always
define a nil constant for any interesting type.
Even my record types, whose every field declaration
has a default initial expression, also gets a nil_type
constant.

Along those lines, I also define width, image, and value
functions so I get easy instrumentation or I/O facilities
nearly for free.

-- 
Samuel T. Harris, Senior Software Engineer II
Raytheon, Aerospace Engineering Services
"If you can make it, We can fake it!"



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

end of thread, other threads:[~2001-08-23 14:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-22 13:34 Stream_Element_Array and an empty array 
2001-08-22 13:42 ` Samuel Tardieu
2001-08-22 13:56   ` Reivilo Snuved
2001-08-22 14:19     ` 
2001-08-22 14:25       ` 
2001-08-22 14:28         ` Florian Weimer
2001-08-22 14:37           ` 
2001-08-22 14:28       ` David C. Hoos
2001-08-22 15:13       ` Claude SIMON
2001-08-22 14:54   ` Ted Dennison
2001-08-22 14:22 ` Samuel T. Harris
2001-08-23  8:37   ` Philip Anderson
2001-08-23 14:02     ` Samuel T. Harris

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