comp.lang.ada
 help / color / mirror / Atom feed
* Beginer problem: variable array size
@ 2002-09-15 14:53 Nacho
  2002-09-15 16:45 ` Larry Kilgallen
                   ` (2 more replies)
  0 siblings, 3 replies; 62+ messages in thread
From: Nacho @ 2002-09-15 14:53 UTC (permalink / raw)


Hi everyone!

I am learning ada and i have to implement an array of unknown size until
rutime.
The array must be resizable at runtime. This is easy to achieve for me in
other lenguajes like c++, but i am new to ada and i don't know hot to
resolve the problem. The solution in c++ code could be:



int variable=50;    //let's make an array of 50 elements.
int* p;    //pointer to int, if the array is of integers.
p=new int[variable];    //we reserve memory for 50 integers.


....  //some code with the array here.

delete [] p;    //we free the allocated memory for the array.
variable=80;    //we change the size of the array.
p=new int[variable];    //we have a new array with the new size.




How can I do the same in ada?
How can I use dinamics arrays of variable size in ada?

I am sorry for my poor English.

Thanks.





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

* Re: Beginer problem: variable array size
  2002-09-15 16:45 ` Larry Kilgallen
@ 2002-09-15 16:16   ` Nacho
  2002-09-15 16:26     ` Ludovic Brenta
                       ` (6 more replies)
  0 siblings, 7 replies; 62+ messages in thread
From: Nacho @ 2002-09-15 16:16 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2277 bytes --]

That does not resolve the problem. I need to change the size of the array
after it has been created. With your solution once array_called_p has been
created it will never change its size.

I need this:

 ... preceding Ada statements
 declare -- scope of array_called_p
     type my_array_type is array ( positive range <> ) of integer;
     array_called_p : my_array_type ( 1 .. variable );
 begin -- scope of array_called_p
     ... Ada statements that use array_called_p

    variable := variable+50;    -- We increase the size of the array in 50
elementes
    ....    HERE I need array_called_p to increase its size so it can hold
50 more elements

 end; -- scope of array_called_p
 ... following Ada statements




The solution in c++ is easy as I posted before. Simply free the memory and
reserve new memory to hold the new size of the array.




"Larry Kilgallen" <Kilgallen@SpamCop.net> escribi� en el mensaje
news:HFiRcRlG5JiR@eisner.encompasserve.org...
> In article <am26u4$d2q$1@nsnmpen2-gest.nuria.telefonica-data.net>, "Nacho"
<NACHANGA@terra.es> writes:
> > Hi everyone!
> >
> > I am learning ada and i have to implement an array of unknown size until
> > rutime.
> > The array must be resizable at runtime. This is easy to achieve for me
in
> > other lenguajes like c++, but i am new to ada and i don't know hot to
> > resolve the problem. The solution in c++ code could be:
> >
> >
> >
> > int variable=50;    //let's make an array of 50 elements.
> > int* p;    //pointer to int, if the array is of integers.
> > p=new int[variable];    //we reserve memory for 50 integers.
> >
> >
> > ....  //some code with the array here.
> >
> > delete [] p;    //we free the allocated memory for the array.
> > variable=80;    //we change the size of the array.
> > p=new int[variable];    //we have a new array with the new size.
>
> Wow, C looks like a lot of work !!!!!
>
> ... preceding Ada statements
>
> declare -- scope of array_called_p
>     type my_array_type is array ( positive range <> ) of integer;
>     array_called_p : my_array_type ( 1 .. variable );
> begin -- scope of array_called_p
>     ... Ada statements that use array_called_p
> end; -- scope of array_called_p
>
> ... following Ada statements
>
> In general, Ada rarely requires pointers.





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

* Re: Beginer problem: variable array size
  2002-09-15 16:16   ` Nacho
@ 2002-09-15 16:26     ` Ludovic Brenta
  2002-09-15 17:46     ` Jeffrey Carter
                       ` (5 subsequent siblings)
  6 siblings, 0 replies; 62+ messages in thread
From: Ludovic Brenta @ 2002-09-15 16:26 UTC (permalink / raw)


On Sun, 15 Sep 2002 18:16:51 +0200, Nacho wrote:
> That does not resolve the problem. I need to change the size of the
> array after it has been created. With your solution once array_called_p
> has been created it will never change its size.

Yes, that's what I thought too.  How about this:

with Ada.Text_Io, Ada.Unchecked_Deallocation;
procedure Vararray is
   type Var_Array is array(Positive range <>) of Integer;
   type Var_Array_Access is access Var_Array;
   Size : Positive;
   Variable : Var_Array_Access;
   procedure Free is new
     Ada.Unchecked_Deallocation(Var_Array, Var_Array_Access);
begin
   Size := 50;
   Variable := new Var_Array(1..Size);
   for I in Variable'Range loop
      Variable(I) := I;
      Ada.Text_Io.Put_Line("var_array(" & Integer'Image(I) & ") = " &
                           Integer'Image(I));
   end loop;
   Free(Variable);

   Size := 80;
   Variable := new Var_Array(1..Size);
   for I in Variable'Range loop
      variable(I) := I;
      Ada.Text_Io.Put_Line("var_array(" & Integer'Image(I) & ") = " &
                           Integer'Image(I));
   end loop;
   Free(Variable);
end Vararray;


HTH

--
Ludovic Brenta.



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

* Re: Beginer problem: variable array size
  2002-09-15 14:53 Beginer problem: variable array size Nacho
@ 2002-09-15 16:45 ` Larry Kilgallen
  2002-09-15 16:16   ` Nacho
  2002-09-17 10:20 ` Georg Bauhaus
  2002-10-02 15:04 ` Matthew Heaney
  2 siblings, 1 reply; 62+ messages in thread
From: Larry Kilgallen @ 2002-09-15 16:45 UTC (permalink / raw)


In article <am26u4$d2q$1@nsnmpen2-gest.nuria.telefonica-data.net>, "Nacho" <NACHANGA@terra.es> writes:
> Hi everyone!
> 
> I am learning ada and i have to implement an array of unknown size until
> rutime.
> The array must be resizable at runtime. This is easy to achieve for me in
> other lenguajes like c++, but i am new to ada and i don't know hot to
> resolve the problem. The solution in c++ code could be:
> 
> 
> 
> int variable=50;    //let's make an array of 50 elements.
> int* p;    //pointer to int, if the array is of integers.
> p=new int[variable];    //we reserve memory for 50 integers.
> 
> 
> ....  //some code with the array here.
> 
> delete [] p;    //we free the allocated memory for the array.
> variable=80;    //we change the size of the array.
> p=new int[variable];    //we have a new array with the new size.

Wow, C looks like a lot of work !!!!!

	... preceding Ada statements

	declare	-- scope of array_called_p
	    type my_array_type is array ( positive range <> ) of integer;
	    array_called_p : my_array_type ( 1 .. variable );
	begin	-- scope of array_called_p
	    ... Ada statements that use array_called_p
	end;	-- scope of array_called_p

	... following Ada statements

In general, Ada rarely requires pointers.



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

* Re: Beginer problem: variable array size
  2002-09-15 16:16   ` Nacho
  2002-09-15 16:26     ` Ludovic Brenta
@ 2002-09-15 17:46     ` Jeffrey Carter
  2002-09-15 18:27     ` Pascal Obry
                       ` (4 subsequent siblings)
  6 siblings, 0 replies; 62+ messages in thread
From: Jeffrey Carter @ 2002-09-15 17:46 UTC (permalink / raw)


Nacho wrote:
> That does not resolve the problem. I need to change the size of the array
> after it has been created. With your solution once array_called_p has been
> created it will never change its size.
> 
> I need this:
> 
>  ... preceding Ada statements
>  declare -- scope of array_called_p
>      type my_array_type is array ( positive range <> ) of integer;
>      array_called_p : my_array_type ( 1 .. variable );
>  begin -- scope of array_called_p
>      ... Ada statements that use array_called_p
> 
>     variable := variable+50;    -- We increase the size of the array in 50
> elementes
>     ....    HERE I need array_called_p to increase its size so it can hold
> 50 more elements
> 
>  end; -- scope of array_called_p
>  ... following Ada statements

It may solve your problem. Consider

Multiple_Arrays : loop
    ...

    Size := Some_Function;
    -- Some_Function may be a random number generator,
    -- obtain the value interactively from the user, or
    -- so on

    ...

    Scope_Of_P : declare
       P : Some_Array_Type (1 .. Size);
    begin -- Scope_Of_P
       ...
    end Scope_Of_P;

    ...
end loop Multiple_Arrays;

Here you deal repeatedly with an array named P, with a different size 
each time. And, look Ma!, no pointers.

Of course, if you design your program with the assumption that P has to 
be implemented using pointers, then this approach may not fit into your 
design. But that is a problem with your design, not with this approach.

Certainly it is possible to use arrays as in C, but it is rarely 
necessary. In your C++ example, you do not have one array with 2 
different sizes, you have two arrays, accessed misleadingly through the 
same pointer. The 2nd array has nothing to do with the first, which no 
longer exists, having been freed. In Ada, this would involve a second 
block statement declaring a second array. Still no pointers? Sorry.

-- 
Jeff Carter
"Son of a window-dresser."
Monty Python & the Holy Grail




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

* Re: Beginer problem: variable array size
  2002-09-15 16:16   ` Nacho
  2002-09-15 16:26     ` Ludovic Brenta
  2002-09-15 17:46     ` Jeffrey Carter
@ 2002-09-15 18:27     ` Pascal Obry
  2002-09-15 20:03     ` Larry Kilgallen
                       ` (3 subsequent siblings)
  6 siblings, 0 replies; 62+ messages in thread
From: Pascal Obry @ 2002-09-15 18:27 UTC (permalink / raw)



"Nacho" <NACHANGA@terra.es> writes:

> That does not resolve the problem. I need to change the size of the array
> after it has been created. With your solution once array_called_p has been
> created it will never change its size.

If you really want to have an array changing its size and keeping its current
values I think you should build a proper abstraction and use it. It is a pain
and error prone to call new/free in your code. If you are using GNAT you
could use GNAT.Dynamic_Tables.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Beginer problem: variable array size
  2002-09-15 16:16   ` Nacho
                       ` (2 preceding siblings ...)
  2002-09-15 18:27     ` Pascal Obry
@ 2002-09-15 20:03     ` Larry Kilgallen
  2002-09-17 14:22     ` Ted Dennison
                       ` (2 subsequent siblings)
  6 siblings, 0 replies; 62+ messages in thread
From: Larry Kilgallen @ 2002-09-15 20:03 UTC (permalink / raw)


In article <am2bq5$8fl$1@nsnmpen2-gest.nuria.telefonica-data.net>, "Nacho" <NACHANGA@terra.es> writes:
> That does not resolve the problem. I need to change the size of the array
> after it has been created. With your solution once array_called_p has been
> created it will never change its size.

In fact, it will disappear entirely and be recreated the next
time around the loop or the next time into the subroutine.

I believe you are trying to force-fit a C-style approach to solving
the problem in Ada, which is never a good idea.  Remember the old
saying:

	You can write Fortran in any language.



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

* Re: Beginer problem: variable array size
  2002-09-15 14:53 Beginer problem: variable array size Nacho
  2002-09-15 16:45 ` Larry Kilgallen
@ 2002-09-17 10:20 ` Georg Bauhaus
  2002-10-02 15:04 ` Matthew Heaney
  2 siblings, 0 replies; 62+ messages in thread
From: Georg Bauhaus @ 2002-09-17 10:20 UTC (permalink / raw)


Nacho <NACHANGA@terra.es> wrote:
: int variable=50;    //let's make an array of 50 elements.
: int* p;    //pointer to int, if the array is of integers.
: p=new int[variable];    //we reserve memory for 50 integers.
: delete [] p;    //we free the allocated memory for the array.
: variable=80;    //we change the size of the array.
: p=new int[variable];    //we have a new array with the new size.

Hm. You said you wanted to resize p.
If I'm not mistaken then you are creating two unrelated arrays
of different sizes (new), and in each case you let p point to
the newly created array. That is, the int values of the firsts
instance of p need not be present in the second instance of p?
I think this isn't what "resizing an array" usually means.

However, the Ada solution Larry has given shows the way to
the same solution in Ada. You just create two different
array values and name them where you need them.

If you are working with two completely different arrays anyway,
that happen to be pointed to by the same pointer variable,
then why not consider separating the solutions into related
parts? (As you don't seem to work with values from "the 1st p"
in "the 2nd p".)

-- Georg



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

* Re: Beginer problem: variable array size
  2002-09-15 16:16   ` Nacho
                       ` (3 preceding siblings ...)
  2002-09-15 20:03     ` Larry Kilgallen
@ 2002-09-17 14:22     ` Ted Dennison
  2002-09-18 11:53       ` Marin David Condic
  2002-09-19  0:43     ` Robert A Duff
  2002-09-19 20:25     ` Brian Gaffney
  6 siblings, 1 reply; 62+ messages in thread
From: Ted Dennison @ 2002-09-17 14:22 UTC (permalink / raw)


"Nacho" <NACHANGA@terra.es> wrote in message news:<am2bq5$8fl$1@nsnmpen2-gest.nuria.telefonica-data.net>...
> That does not resolve the problem. I need to change the size of the array
> after it has been created. With your solution once array_called_p has been
> created it will never change its size.

Why?

Its very rare that someone actually needs to change the size of an
array after it has been created. If you don't know the size of the
array until point X, you can almost always wait to declare the array
until point X. Good Ada code generally declares arrays of the exact
size needed, often as constants. C doesn't let you do this as easily,
so most folk don't do things that way in C. But don't let C's lack of
capability hamstring your Ada code.

Even if you have to work on the array to find its true length (a very
rare occurance), there are ways to declare it properly on the stack
without using any (explicit) dynamic allocation. One of our favorite
tricks here in c.l.a. is using recursive routines that return
unconstrained array types. For an example of this technique, go look
at http://www.adapower.com/lang/recstring.html . This does exactly
what you are trying to do with your example below, except it uses
character arrays, and the step is 256 elements instead of 50.

>  ... preceding Ada statements
>  declare -- scope of array_called_p
>      type my_array_type is array ( positive range <> ) of integer;
>      array_called_p : my_array_type ( 1 .. variable );
>  begin -- scope of array_called_p
>      ... Ada statements that use array_called_p
> 
>     variable := variable+50;    -- We increase the size of the array in 50
> elementes
>     ....    HERE I need array_called_p to increase its size so it can hold
> 50 more elements
> 
>  end; -- scope of array_called_p
>  ... following Ada statements



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

* Re: Beginer problem: variable array size
  2002-09-17 14:22     ` Ted Dennison
@ 2002-09-18 11:53       ` Marin David Condic
  2002-10-02 15:08         ` Matthew Heaney
  0 siblings, 1 reply; 62+ messages in thread
From: Marin David Condic @ 2002-09-18 11:53 UTC (permalink / raw)


Sometimes people like to use arrays as if they were lists. Ada doesn't have
a standard list type, so there's no pointing them in that direction. Dynamic
arrays exist in some languages - just not in Ada. (Well, O.K.
Unbounded_String, but that's not a general array type.) The good news is
that neither does C, so in either language, the OP would have to go about
creating his own construct. Maybe C++ has a dynamic array class?

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Ted Dennison <dennison@telepath.com> wrote in message
news:4519e058.0209170622.498a17e7@posting.google.com...
>
> Why?
>






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

* Re: Beginer problem: variable array size
  2002-09-15 16:16   ` Nacho
                       ` (4 preceding siblings ...)
  2002-09-17 14:22     ` Ted Dennison
@ 2002-09-19  0:43     ` Robert A Duff
  2002-09-19  1:25       ` Jeffrey Carter
                         ` (3 more replies)
  2002-09-19 20:25     ` Brian Gaffney
  6 siblings, 4 replies; 62+ messages in thread
From: Robert A Duff @ 2002-09-19  0:43 UTC (permalink / raw)


"Nacho" <NACHANGA@terra.es> writes:

> That does not resolve the problem. I need to change the size of the array
> after it has been created. With your solution once array_called_p has been
> created it will never change its size.

Right.  You've been admonished about considering the "proper Ada" way of
allocating arrays local to a scope.  You should consider those, but
those require that the array size be known at the point of creation.
There are many cases where you really need to change the size of an
existing array (despite the admonishments that this is rare -- I think
it's common).

> The solution in c++ is easy as I posted before. Simply free the memory and
> reserve new memory to hold the new size of the array.

The solution is what Ludovic Brenta said: you do essentially the
same as in C++ -- you deallocate and reallocate the array.

And Pascal Obry gave good advice to encapsulate this in an abstraction.
Look at the implementation of Ada.Strings.Unbounded, which is a
size-changing array of characters.

It's usually better to allocate exponentially-more space each time a
reallocate-and-copy is needed.

- Bob



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

* Re: Beginer problem: variable array size
  2002-09-19  0:43     ` Robert A Duff
@ 2002-09-19  1:25       ` Jeffrey Carter
  2002-09-19 14:17       ` Hyman Rosen
                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 62+ messages in thread
From: Jeffrey Carter @ 2002-09-19  1:25 UTC (permalink / raw)


Robert A Duff wrote:
> "Nacho" <NACHANGA@terra.es> writes:
> 
> 
>>That does not resolve the problem. I need to change the size of the array
>>after it has been created. With your solution once array_called_p has been
>>created it will never change its size.
> 
> 
> Right.  You've been admonished about considering the "proper Ada" way of
> allocating arrays local to a scope.  You should consider those, but
> those require that the array size be known at the point of creation.
> There are many cases where you really need to change the size of an
> existing array (despite the admonishments that this is rare -- I think
> it's common).

With all due respect to the person responsible for alligators in Ada, 
the C++ example showed 2 independent arrays, the sizes of which were 
known at the point of creation. For such an example, the use of local 
scopes to declare the arrays is probably safer and faster than messing 
around with pointers. Certainly there are times when an array needs to 
be resized, but this example isn't one of them.

-- 
Jeff Carter
"We burst our pimples at you."
Monty Python & the Holy Grail




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

* Re: Beginer problem: variable array size
  2002-09-19  0:43     ` Robert A Duff
  2002-09-19  1:25       ` Jeffrey Carter
@ 2002-09-19 14:17       ` Hyman Rosen
  2002-09-20  3:06       ` Munch
  2002-10-02 15:13       ` Matthew Heaney
  3 siblings, 0 replies; 62+ messages in thread
From: Hyman Rosen @ 2002-09-19 14:17 UTC (permalink / raw)


Robert A Duff wrote:
> "Nacho" <NACHANGA@terra.es> writes:n
>>The solution in c++ is easy as I posted before. Simply free the memory and
>>reserve new memory to hold the new size of the array.n
> 
> The solution is what Ludovic Brenta said: you do essentially the
> same as in C++ -- you deallocate and reallocate the array.
> 
> And Pascal Obry gave good advice to encapsulate this in an abstraction.n

And in C++, you would not be playing with the memory yourself,
because C++ already provides the abstraction for you. It's called
std::vector.




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

* Re: Beginer problem: variable array size
  2002-09-15 16:16   ` Nacho
                       ` (5 preceding siblings ...)
  2002-09-19  0:43     ` Robert A Duff
@ 2002-09-19 20:25     ` Brian Gaffney
  6 siblings, 0 replies; 62+ messages in thread
From: Brian Gaffney @ 2002-09-19 20:25 UTC (permalink / raw)


"Nacho" <NACHANGA@terra.es> wrote in message news:<am2bq5$8fl$1@nsnmpen2-gest.nuria.telefonica-data.net>...
> That does not resolve the problem. I need to change the size of the array
> after it has been created. With your solution once array_called_p has been
> created it will never change its size.
> 
Larry just didn't post enough of the Ada code.  Here is a complete
program that shows how to do what you want:

   with Gnat.IO;
procedure Var is
   Variable : Integer := 50;
   type Int_Array is array (Integer range <>) of Integer;
begin
   for i in 1 .. 2 loop
      declare
         P : Int_Array(1..Variable) := (others => 0);
      begin
         for J in P'range loop
            Gnat.IO.Put(P(J)'img);
         end loop;
         Gnat.IO.New_Line;
      end;
      Variable := 80;
   end loop;
end Var;

Prints a row of 50 0's followed by a row of 80 0's.



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

* Re: Beginer problem: variable array size
  2002-09-19  0:43     ` Robert A Duff
  2002-09-19  1:25       ` Jeffrey Carter
  2002-09-19 14:17       ` Hyman Rosen
@ 2002-09-20  3:06       ` Munch
  2002-09-20  4:49         ` Jim Rogers
                           ` (2 more replies)
  2002-10-02 15:13       ` Matthew Heaney
  3 siblings, 3 replies; 62+ messages in thread
From: Munch @ 2002-09-20  3:06 UTC (permalink / raw)


I think this is funny, almost every programming class that i've ever
taken when you start a new language i swear I always do the same first
two programs.
1. Hello World
2. The one that has the problem that apparently in ada takes a page of
code where in C++ it takes about 4 lines.

The problem is:  Prompt the user to enter in an Integers followed by
pressing <enter>, enter a 0 to terminate.  At no point have a set
ceiling on how many integers can be in the array.  Sort using whatever
sort algorithm makes you happy then display.

I'm not elite programmer but I only see a few ways to easily (man
thats relative) to accomplish this in Ada.
1. Implement a Linked List class and make it so that each node holds
an Int.  this seems like an over kill being as you successfully double
the memory being consumed since every integer will have a head
attached to it.

2. Implement a stack. Okay so I have to implement another abstract
data type just to accomplish what inherently is a simple list problem.

3. Queue same as stack.

Nacho pointed out that C++/C takes very few lines of code to
accomplish this task.  however ada will require me to write an entire
sub-program or class just to accomplish this basic task.

The one thing i haven't looked into is to see if there is a string
tokenizer (is that what its called/) built in.  basically read the
numbers in and appened them to the end of an unbound string ( i know i
saw that somewhere).  Then parse it looking for spaces and converting
the characters to their int form making the array then and copying
them over.  Again seems like I'm going From new york to new jersey but
i've got a lay over in los angeles....*sigh*



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

* Re: Beginer problem: variable array size
  2002-09-20  3:06       ` Munch
@ 2002-09-20  4:49         ` Jim Rogers
  2002-09-20  6:35         ` tmoran
  2002-09-20 12:11         ` Marin David Condic
  2 siblings, 0 replies; 62+ messages in thread
From: Jim Rogers @ 2002-09-20  4:49 UTC (permalink / raw)


Munch wrote:

> 
> The one thing i haven't looked into is to see if there is a string
> tokenizer (is that what its called/) built in.  basically read the
> numbers in and appened them to the end of an unbound string ( i know i
> saw that somewhere).  Then parse it looking for spaces and converting
> the characters to their int form making the array then and copying
> them over.  Again seems like I'm going From new york to new jersey but
> i've got a lay over in los angeles....*sigh*
> 


Yes, Ada does have a built in tokenizer. It can be found in the package
Ada.Strings.Fixed. For what you want, simply read your values into an
unbounded string, convert that string to a fixed length string, then
traverse that string using the indexing and tokenizing subprograms.

Jim Rogers




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

* Re: Beginer problem: variable array size
  2002-09-20  3:06       ` Munch
  2002-09-20  4:49         ` Jim Rogers
@ 2002-09-20  6:35         ` tmoran
  2002-09-20 16:00           ` Pat Rogers
  2002-09-20 12:11         ` Marin David Condic
  2 siblings, 1 reply; 62+ messages in thread
From: tmoran @ 2002-09-20  6:35 UTC (permalink / raw)


>I'm not elite programmer but I only see a few ways to easily
  So because you don't know Ada you don't see how to do it simply, and
therefore Ada is terrible?  That makes a lot of sense.
  Assuming that, unlike your C++ case, you have no access to any
libraries, and trusting you won't hand it in for your homework, I point out:

with Ada.Text_IO;
procedure Munch is
  use Ada.Text_IO;
  package Int_IO is new Integer_IO(Integer);

  type List_Type is array (Integer range <>) of Integer;
  Empty_List: List_Type(1 .. 0);

  function Get return List_Type is
    Datum   : Integer;
  begin
    Put("Enter an integer, or 0 to quit:");
    Int_IO.Get(Datum);
    if Datum = 0 then
      return Empty_List;
    else
      return Datum & Get;
    end if;
  end Get;

  List : List_Type := Get;
  Temp : Integer;

begin
  for I in List'range loop
    for J in I + 1 .. List'Last loop
      if List(I) > List(J) then
        Temp := List(I);
        List(I) := List(J);
        List(J) := Temp;
      end if;
    end loop;
    Put_Line(Integer'Image(List(I)));
  end loop;
end Munch;



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

* Re: Beginer problem: variable array size
  2002-09-20  3:06       ` Munch
  2002-09-20  4:49         ` Jim Rogers
  2002-09-20  6:35         ` tmoran
@ 2002-09-20 12:11         ` Marin David Condic
  2002-09-20 13:59           ` Larry Kilgallen
                             ` (2 more replies)
  2 siblings, 3 replies; 62+ messages in thread
From: Marin David Condic @ 2002-09-20 12:11 UTC (permalink / raw)


I'll agree with the "Hello World" example, but I've never seen the second
one you cite as an example in a programming class. (Usually, the second
program is "Read in two numbers and add them together...") And its a bit
unfair to pull an example out like this and say "C++ can do this in N lines
and it will take 10*N lines in Ada..." One can *always* rectally extract an
example that makes language X look bad and language Y look good.
(Illustration: "Reduce an N by M matrix of numbers..." - In some languages
this can be done in one instruction. How many instructions does it take in
C++?)

The reality is that by putting a requirement out there that there must be no
limit on the number of elements accepted, you create a difficulty that
doesn't normally exist in the real world. The fact that I can't dynamically
grow an array in Ada without building my own data structure isn't in
practice going to prevent me from accomplishing a job. I just build the data
structure or redefine the problem such that I can do it with a fixed data
structure. Arrays in C++ can't dynamically grow either - you require a data
structure that is built from the primitive ones. So C++ already has it built
and that's nice, but its not something that can't readily be duplicated in
Ada.

If the problem is one of "How do I get my job done..." then the answer is to
get hold of one of the many spiffy Ada libraries out there that will provide
dynamic data structures. If the question is "How come Ada doesn't have any
standard dynamic data structure libraries that ship with every
compiler???" - well, I've been asking that question here for some time now.
:-)

BTW: I'm waiting for Ada to have some standard matrix & vector libraries so
I can post to C++ newsgroups "Why can I multiply two matrices together in
Ada in only one line of code and it takes me ten thousand to do it in
C++..." :-)

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Munch <ramunch@sigecom.net> wrote in message
news:38993b18.0209191906.b56b982@posting.google.com...
>
> The problem is:  Prompt the user to enter in an Integers followed by
> pressing <enter>, enter a 0 to terminate.  At no point have a set
> ceiling on how many integers can be in the array.  Sort using whatever
> sort algorithm makes you happy then display.
>






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

* Re: Beginer problem: variable array size
  2002-09-20 12:11         ` Marin David Condic
@ 2002-09-20 13:59           ` Larry Kilgallen
  2002-09-20 14:55             ` Hyman Rosen
  2002-09-22 12:49             ` Marin David Condic
  2002-09-20 16:28           ` Warren W. Gay VE3WWG
  2002-09-21 22:23           ` tmoran
  2 siblings, 2 replies; 62+ messages in thread
From: Larry Kilgallen @ 2002-09-20 13:59 UTC (permalink / raw)


In article <amf3i7$v68$1@slb5.atl.mindspring.net>, "Marin David Condic" <mcondic.auntie.spam@acm.org> writes:

> structure. Arrays in C++ can't dynamically grow either - you require a data
> structure that is built from the primitive ones. So C++ already has it built
> and that's nice, but its not something that can't readily be duplicated in
> Ada.

Does C++ also have a built-in Sort primitive ?

> BTW: I'm waiting for Ada to have some standard matrix & vector libraries so
> I can post to C++ newsgroups "Why can I multiply two matrices together in
> Ada in only one line of code and it takes me ten thousand to do it in
> C++..." :-)

The number ten thousand must not be presuming unlimited length vectors :-)



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

* Re: Beginer problem: variable array size
  2002-09-20 13:59           ` Larry Kilgallen
@ 2002-09-20 14:55             ` Hyman Rosen
  2002-09-20 16:10               ` Larry Kilgallen
                                 ` (3 more replies)
  2002-09-22 12:49             ` Marin David Condic
  1 sibling, 4 replies; 62+ messages in thread
From: Hyman Rosen @ 2002-09-20 14:55 UTC (permalink / raw)


Larry Kilgallen wrote:
> Does C++ also have a built-in Sort primitive ?

C++ has sorting algorithms as part of its standard library.
It's got a regular sort, a stable sort, a partial sort,
and a couple of related things. They're all written as
templates, so the compare and swap portions can be inlined,
giving much better performance than the old C qsort which
uses a pointer to function to do comparisons.

I think I'm becoming more used to Ada :-) When I saw the
problem posed by the OP, I immediately thought of using
a recursive function that built up and returned arrays,
similar to what tmoran posted.

MDC wrote:
 > The reality is that by putting a requirement out there
 > that there must be no limit on the number of elements
 > accepted, you create a difficulty that doesn't normally
 > exist in the real world.

I've talked about this before. Until the GNU people came
along and rewrote the UNIX text utilities, they would
constantly and inconsistently return wrong results because
of arbitrary limits, such as maximum line sizes. To this day,
I cannot use vi on a Sun in an xterm that is "too wide". I
have had text files with lines that were longer than 100000
characters which I needed to process. Wiring arbitrary limits
into a program because you think that they are large enough
for all uses is a recipe for disaster.




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

* Re: Beginer problem: variable array size
  2002-09-20  6:35         ` tmoran
@ 2002-09-20 16:00           ` Pat Rogers
  2002-09-20 16:07             ` Preben Randhol
  0 siblings, 1 reply; 62+ messages in thread
From: Pat Rogers @ 2002-09-20 16:00 UTC (permalink / raw)


<tmoran@acm.org> wrote in message
news:Akzi9.152773$Jo.48440@rwcrnsc53...
<snip>
> with Ada.Text_IO;
> procedure Munch is
>   use Ada.Text_IO;
>   package Int_IO is new Integer_IO(Integer);
>
>   type List_Type is array (Integer range <>) of Integer;
>   Empty_List: List_Type(1 .. 0);
>
>   function Get return List_Type is
>     Datum   : Integer;
>   begin
>     Put("Enter an integer, or 0 to quit:");
>     Int_IO.Get(Datum);
>     if Datum = 0 then
>       return Empty_List;
>     else
>       return Datum & Get;

Where does the function "&"( Left : Integer; Right : List_Type )
return List_Type come from?

>     end if;
>   end Get;
>
>   List : List_Type := Get;
>   Temp : Integer;
>
> begin
>   for I in List'range loop
>     for J in I + 1 .. List'Last loop
>       if List(I) > List(J) then
>         Temp := List(I);
>         List(I) := List(J);
>         List(J) := Temp;
>       end if;
>     end loop;
>     Put_Line(Integer'Image(List(I)));
>   end loop;
> end Munch;





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

* Re: Beginer problem: variable array size
  2002-09-20 16:00           ` Pat Rogers
@ 2002-09-20 16:07             ` Preben Randhol
  2002-09-20 20:15               ` Pat Rogers
  0 siblings, 1 reply; 62+ messages in thread
From: Preben Randhol @ 2002-09-20 16:07 UTC (permalink / raw)


On Fri, 20 Sep 2002 16:00:52 GMT, Pat Rogers wrote:
> 
> Where does the function "&"( Left : Integer; Right : List_Type )
> return List_Type come from?

ARM95: 4.5.3 states:

  [...]
  
  3. The concatenation operators & are predefined for every nonlimited,
     one-dimensional array type T with component type C. They have the
     following specifications:

  4.      function "&"(Left : T; Right : T) return T
          function "&"(Left : T; Right : C) return T
          function "&"(Left : C; Right : T) return T
          function "&"(Left : C; Right : C) return T

Preben



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

* Re: Beginer problem: variable array size
  2002-09-20 14:55             ` Hyman Rosen
@ 2002-09-20 16:10               ` Larry Kilgallen
  2002-09-20 16:31               ` Warren W. Gay VE3WWG
                                 ` (2 subsequent siblings)
  3 siblings, 0 replies; 62+ messages in thread
From: Larry Kilgallen @ 2002-09-20 16:10 UTC (permalink / raw)


In article <1032533590.712308@master.nyc.kbcfp.com>, Hyman Rosen <hyrosen@mail.com> writes:

> I think I'm becoming more used to Ada :-) When I saw the
> problem posed by the OP, I immediately thought of using
> a recursive function that built up and returned arrays,
> similar to what tmoran posted.

So even though one _can_ write Fortran in any language,
one is not _required_ to do so !



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

* Re: Beginer problem: variable array size
  2002-09-20 12:11         ` Marin David Condic
  2002-09-20 13:59           ` Larry Kilgallen
@ 2002-09-20 16:28           ` Warren W. Gay VE3WWG
  2002-09-20 17:49             ` Hyman Rosen
  2002-09-22 13:18             ` Marin David Condic
  2002-09-21 22:23           ` tmoran
  2 siblings, 2 replies; 62+ messages in thread
From: Warren W. Gay VE3WWG @ 2002-09-20 16:28 UTC (permalink / raw)


Marin David Condic wrote:
...
> If the problem is one of "How do I get my job done..." then the answer is to
> get hold of one of the many spiffy Ada libraries out there that will provide
> dynamic data structures. If the question is "How come Ada doesn't have any
> standard dynamic data structure libraries that ship with every
> compiler???" - well, I've been asking that question here for some time now.
> :-)
...
> MDC

My observation that I would like to add here is that Ada programmers have
higher standards than C++ WRT their libraries. The C++ STL for example,
would (I assume) not cut it for many/most realtime systems because of
the amount of dynamic memory assignments that take place behind the
scenes in the STL routines (ignoring safety issues for the moment).

Whereas the Ada programmer wants a library (as a lofty goal) that can
be used both in the general purpose world and be useful in the
realtime world.  Based upon some of the posts I've seen over the last
year it might be more practical to fork two different libraries for
this reason (this has already been suggested I think). Yet, it would
be truly nice if they both had the same general signatures where
possible.

Bottom line: The C++ programmer likes to criticize the Ada world for
a lack of STL equivalent whereas this doesn't exist in Ada95 perhaps
because the Ada programmer is attempting to solve a more difficult
problem -- one that the C++ programmer often doesn't understand.

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




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

* Re: Beginer problem: variable array size
  2002-09-20 14:55             ` Hyman Rosen
  2002-09-20 16:10               ` Larry Kilgallen
@ 2002-09-20 16:31               ` Warren W. Gay VE3WWG
  2002-09-24 12:41                 ` Thomas Dickey
  2002-09-21 10:44               ` Thomas Dickey
  2002-09-22 13:00               ` Marin David Condic
  3 siblings, 1 reply; 62+ messages in thread
From: Warren W. Gay VE3WWG @ 2002-09-20 16:31 UTC (permalink / raw)


Hyman Rosen wrote:
> Larry Kilgallen wrote:
...
> MDC wrote:
>  > The reality is that by putting a requirement out there
>  > that there must be no limit on the number of elements
>  > accepted, you create a difficulty that doesn't normally
>  > exist in the real world.
> 
> I've talked about this before. Until the GNU people came
> along and rewrote the UNIX text utilities, they would
> constantly and inconsistently return wrong results because
> of arbitrary limits, such as maximum line sizes. To this day,
> I cannot use vi on a Sun in an xterm that is "too wide".
...

I remember hitting line length limits on SCO UNIX's _xterm_
sessions. Grrrr.

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




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

* Re: Beginer problem: variable array size
  2002-09-20 16:28           ` Warren W. Gay VE3WWG
@ 2002-09-20 17:49             ` Hyman Rosen
  2002-09-21  7:30               ` Preben Randhol
  2002-09-22  3:34               ` Ted Dennison
  2002-09-22 13:18             ` Marin David Condic
  1 sibling, 2 replies; 62+ messages in thread
From: Hyman Rosen @ 2002-09-20 17:49 UTC (permalink / raw)


Warren W. Gay VE3WWG wrote:
> The C++ STL for example,
> would (I assume) not cut it for many/most realtime systems because of
> the amount of dynamic memory assignments that take place behind the
> scenes in the STL routines

The amount of memory allocation in the STL is predictable.

> Bottom line: The C++ programmer likes to criticize the Ada world

The C++ programmer ignores the Ada world, I'm afraid.




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

* Re: Beginer problem: variable array size
  2002-09-20 16:07             ` Preben Randhol
@ 2002-09-20 20:15               ` Pat Rogers
  0 siblings, 0 replies; 62+ messages in thread
From: Pat Rogers @ 2002-09-20 20:15 UTC (permalink / raw)


"Preben Randhol" <randhol+abuse@pvv.org> wrote in message
news:slrnaomhr7.6q6.randhol+abuse@kiuk0152.chembio.ntnu.no...
> On Fri, 20 Sep 2002 16:00:52 GMT, Pat Rogers wrote:
> >
> > Where does the function "&"( Left : Integer; Right : List_Type )
> > return List_Type come from?
>
> ARM95: 4.5.3 states:
>
>   [...]
>
>   3. The concatenation operators & are predefined for every
nonlimited,
>      one-dimensional array type T with component type C. They have
the
>      following specifications:
>
>   4.      function "&"(Left : T; Right : T) return T
>           function "&"(Left : T; Right : C) return T
>           function "&"(Left : C; Right : T) return T
>           function "&"(Left : C; Right : C) return T


Ah yes, right.  Thanks!





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

* Re: Beginer problem: variable array size
  2002-09-20 17:49             ` Hyman Rosen
@ 2002-09-21  7:30               ` Preben Randhol
  2002-09-23 13:41                 ` Hyman Rosen
  2002-09-22  3:34               ` Ted Dennison
  1 sibling, 1 reply; 62+ messages in thread
From: Preben Randhol @ 2002-09-21  7:30 UTC (permalink / raw)


On Fri, 20 Sep 2002 13:49:34 -0400, Hyman Rosen wrote:
> 
> The C++ programmer ignores the Ada world, I'm afraid.
                     ^^^^^^^
                     is ignorant of

Preben
-- 
Preben Randhol  --------------------  http://www.pvv.org/~randhol
�.., chaos is found in greatest abundance wherever order is being
sought. It always defeats order, because it is better organized.�
                            -- Interesting Times, Terry Pratchett



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

* Re: Beginer problem: variable array size
  2002-09-20 14:55             ` Hyman Rosen
  2002-09-20 16:10               ` Larry Kilgallen
  2002-09-20 16:31               ` Warren W. Gay VE3WWG
@ 2002-09-21 10:44               ` Thomas Dickey
  2002-09-23 13:37                 ` Hyman Rosen
  2002-09-22 13:00               ` Marin David Condic
  3 siblings, 1 reply; 62+ messages in thread
From: Thomas Dickey @ 2002-09-21 10:44 UTC (permalink / raw)


Hyman Rosen <hyrosen@mail.com> wrote:

> I've talked about this before. Until the GNU people came
> along and rewrote the UNIX text utilities, they would
> constantly and inconsistently return wrong results because
> of arbitrary limits, such as maximum line sizes. To this day,
> I cannot use vi on a Sun in an xterm that is "too wide". I
> have had text files with lines that were longer than 100000
> characters which I needed to process. Wiring arbitrary limits
> into a program because you think that they are large enough
> for all uses is a recipe for disaster.

however, none of the vi-clones were written by anyone associated with GNU.

point being that rewrites are done with 20-20 hindsight and more resources...

-- 
Thomas E. Dickey <dickey@radix.net> <dickey@herndon4.his.com>
http://dickey.his.com
ftp://dickey.his.com



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

* Re: Beginer problem: variable array size
  2002-09-20 12:11         ` Marin David Condic
  2002-09-20 13:59           ` Larry Kilgallen
  2002-09-20 16:28           ` Warren W. Gay VE3WWG
@ 2002-09-21 22:23           ` tmoran
  2002-09-23 13:53             ` Hyman Rosen
  2 siblings, 1 reply; 62+ messages in thread
From: tmoran @ 2002-09-21 22:23 UTC (permalink / raw)


>The reality is that by putting a requirement out there that there must be no
>limit on the number of elements accepted, you create a difficulty that
>doesn't normally exist in the real world.
  I'd rephrase that as "you fudge away a difficulty that does exist in the
real world".  Obviously no program on a real computer will accept a truly
unlimited amount of input, and certainly not in a finite length of time.
It's just that by not explicitly dimensioning an array you make it seem as
if the input is umlimited.  If you use, for instance, a quadratic sort,
you're probably in fact limited to a few thousand elements before things
get totally unreasonable.  Given that input is coming from a user,
according to the problem statement, you might have 8*3600= 28800 values if
someone input one/second for 8 hours, so using
  List : array(1 .. 8*3600) of Integer;
and a better than quadratic sort is probably much simpler and more
reasonable than a (pretend) "no limit".  I think the prof's problem
statement should have ended with "Document and justify any assumptions
you had to make because of missing details in the problem statement."
  If the intent is to teach about linked lists and dynamic arrays,
a more realistic, and thus more convincing, problem with multiple
collections of various sizes, but a certain maximum sum of sizes,
would be better.



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

* Re: Beginer problem: variable array size
  2002-09-20 17:49             ` Hyman Rosen
  2002-09-21  7:30               ` Preben Randhol
@ 2002-09-22  3:34               ` Ted Dennison
  1 sibling, 0 replies; 62+ messages in thread
From: Ted Dennison @ 2002-09-22  3:34 UTC (permalink / raw)


Hyman Rosen wrote:
> Warren W. Gay VE3WWG wrote:
> 
>> The C++ STL for example,
>> would (I assume) not cut it for many/most realtime systems because of
>> the amount of dynamic memory assignments that take place behind the
>> scenes in the STL routines
> 
> 
> The amount of memory allocation in the STL is predictable.

Well, no. Its suggested that certian structures not allocate memory 
under certian cirucumstances (eg: Vectors aren't supposed to allocate 
memory during the rest of their runtime if you reserve a certian size up 
front and don't exceed those bounds). But there is no *requirement* that 
any STL template actually works that way. If you care, you really have 
to verify this with your vendor, or decipher the templates to see for 
yourself (good luck!)

To make matters worse, the C++ compilers in the most common use by far, 
Microsoft's Visual C++ 6 and below, use a version of the STL that is 
pre-standard. Those compilers also don't support automatic instantiation 
properly. So many "standard" source code examples won't work on most C++ 
compilers.

> 
>> Bottom line: The C++ programmer likes to criticize the Ada world
> 
> 
> The C++ programmer ignores the Ada world, I'm afraid.

...not to mention their own standard.







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

* Re: Beginer problem: variable array size
  2002-09-20 13:59           ` Larry Kilgallen
  2002-09-20 14:55             ` Hyman Rosen
@ 2002-09-22 12:49             ` Marin David Condic
  1 sibling, 0 replies; 62+ messages in thread
From: Marin David Condic @ 2002-09-22 12:49 UTC (permalink / raw)


No sort *primitive* that I know of, but then neither does Ada, so its not
something to brag about. I don't know for sure about "standard" C++, but
MSVC++ had library packages that could sort data. Ada *could* have it too -
but I suppose that has to wait until 0x. :-)

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Larry Kilgallen <Kilgallen@SpamCop.net> wrote in message
news:qhGf3vGONiwd@eisner.encompasserve.org...
>
> Does C++ also have a built-in Sort primitive ?
>






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

* Re: Beginer problem: variable array size
  2002-09-20 14:55             ` Hyman Rosen
                                 ` (2 preceding siblings ...)
  2002-09-21 10:44               ` Thomas Dickey
@ 2002-09-22 13:00               ` Marin David Condic
  2002-09-26  3:37                 ` Kevin Cline
  3 siblings, 1 reply; 62+ messages in thread
From: Marin David Condic @ 2002-09-22 13:00 UTC (permalink / raw)


Well, as is often the case, the answer is "It Depends". Yes, there are a
number of cases where you don't want to set arbitrary limits on data volume.
Usually, these are of significant enough importance, that going to the
trouble of developing a proper data structure to hold it is not that big a
deal in the grand scheme of things. However, when you're confronted with a
student project or some light-duty, quick and dirty app that reasonably
approximates the case described earlier (punching in a bunch of numbers to
sort...) Its typically not that big a deal to impose some arbitrary (and
large) upper limit if it allows you simplicity of implementation. Not
everything needs to be a brick outhouse. Of course for any sort of serious
production work, its usually the case where you build yourself a library
routine to do the job properly once and then just reuse it thousands of
times. Assuming you have stuff like this, even the quick and dirty hacks
become far more robust at no extra charge. :-)

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Hyman Rosen <hyrosen@mail.com> wrote in message
news:1032533590.712308@master.nyc.kbcfp.com...
>
> I've talked about this before. Until the GNU people came
> along and rewrote the UNIX text utilities, they would
> constantly and inconsistently return wrong results because
> of arbitrary limits, such as maximum line sizes. To this day,
> I cannot use vi on a Sun in an xterm that is "too wide". I
> have had text files with lines that were longer than 100000
> characters which I needed to process. Wiring arbitrary limits
> into a program because you think that they are large enough
> for all uses is a recipe for disaster.
>





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

* Re: Beginer problem: variable array size
  2002-09-20 16:28           ` Warren W. Gay VE3WWG
  2002-09-20 17:49             ` Hyman Rosen
@ 2002-09-22 13:18             ` Marin David Condic
  2002-09-24 16:55               ` Warren W. Gay VE3WWG
  1 sibling, 1 reply; 62+ messages in thread
From: Marin David Condic @ 2002-09-22 13:18 UTC (permalink / raw)


Having watched the debate go on here about the subject of realtime vs
general-purpose libraries, I'd conclude that it would be pretty hopeless to
satisfy everyone's objectives. Especially if the goal is to get something
into the standard rather than simply provide a reference implementation.
From the perspective of the standard, you'd only want to specify a package
spec that *could* be made realtime enough. (No mandate for things that might
screw it up - like garbage collection) You'd almost certainly want to avoid
having a half-dozen or more different flavors of it (realtime vs
non-realtime, task-safe vs non-task-safe, static vs dynamic allocation,
etc....) End of the day, I don't think it is a sufficient excuse that the
Ada programmer wants something more thorough to justify not (and maybe
never) providing libraries.

If eventually something gets into the ARM as a standard library, that's
great. But I think it would be better to get something general-purpose
accepted as a semi-standard in a faster and more flexible manner. Get a
container library out there that is generally accepted as the official Ada
library and start experimenting with it. In a year or so, you'll know what
its weaknesses are and another cut can be made at it. Soon enough you'll
have a stable version that may satisfy 80% of the user's needs. (maybe you
trash the realtime requirement and tell us realtime guys to go pound sand.
we're no worse off than right now where if we want them we've got to write
our own.) If that's achieved, *then* you can talk about getting it into the
standard - complete with detailed descriptions of the exact, verifiable
behavior you need from everything.

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Warren W. Gay VE3WWG <ve3wwg@cogeco.ca> wrote in message
news:3D8B4CC9.5020202@cogeco.ca...
>
> Whereas the Ada programmer wants a library (as a lofty goal) that can
> be used both in the general purpose world and be useful in the
> realtime world.  Based upon some of the posts I've seen over the last
> year it might be more practical to fork two different libraries for
> this reason (this has already been suggested I think). Yet, it would
> be truly nice if they both had the same general signatures where
> possible.
>






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

* Re: Beginer problem: variable array size
  2002-09-21 10:44               ` Thomas Dickey
@ 2002-09-23 13:37                 ` Hyman Rosen
  0 siblings, 0 replies; 62+ messages in thread
From: Hyman Rosen @ 2002-09-23 13:37 UTC (permalink / raw)


Thomas Dickey wrote:
> however, none of the vi-clones were written
 > by anyone associated with GNU.

What is the relevance of this? I don't use a
vi clone on Sun, I use vi.

> point being that rewrites are done with 20-20
 > hindsight and more resources...

The point being that since we now have the hindsight,
we should no longer be advising people to use practices
which limit the size of the data that can be handled.




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

* Re: Beginer problem: variable array size
  2002-09-21  7:30               ` Preben Randhol
@ 2002-09-23 13:41                 ` Hyman Rosen
  0 siblings, 0 replies; 62+ messages in thread
From: Hyman Rosen @ 2002-09-23 13:41 UTC (permalink / raw)


Preben Randhol wrote:
>                      is ignorant of

Yup. As I've said before, a few of us keep mentioning Ada
in the C++ newsgroups as a resource to use when concurrent
programming for C++ is finally designed into the language
standard. We'll see what happens. The mills of the gods
grind slow...




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

* Re: Beginer problem: variable array size
  2002-09-21 22:23           ` tmoran
@ 2002-09-23 13:53             ` Hyman Rosen
  2002-09-23 15:19               ` Chad R. Meiners
                                 ` (2 more replies)
  0 siblings, 3 replies; 62+ messages in thread
From: Hyman Rosen @ 2002-09-23 13:53 UTC (permalink / raw)


tmoran@acm.org wrote:
 > using
>   List : array(1 .. 8*3600) of Integer;
> and a better than quadratic sort is probably much simpler and more
> reasonable than a (pretend) "no limit".

In modern computing environments, programs that take input
from the user are easily hooked up to take input from other
programs or files instead, so working on the assumption that
the program will be used only by a human typist is foolish.
The professor probably has files of input numbers that will
be fed to each submitted program. I'll bet one of them is
very large, to test the input size limit even if the sort
won't complete in a reasonable amount of time.

Furthermore, if you are going to have an arbitrary limit,
you have to provide the extra code to handle the case of
the limit being exceeded. I suppose you could just range
over the size of the array and ignore any extra input. This
is exactly the kind of silently wrong behavior I was talking
about.

And further yet, why do you think you get to rewrite the
given requirements just because they don't suit the style of
your favorite programming language?




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

* Re: Beginer problem: variable array size
  2002-09-23 13:53             ` Hyman Rosen
@ 2002-09-23 15:19               ` Chad R. Meiners
  2002-09-23 16:00                 ` Hyman Rosen
  2002-09-23 17:09               ` tmoran
  2002-09-24 12:36               ` Marin David Condic
  2 siblings, 1 reply; 62+ messages in thread
From: Chad R. Meiners @ 2002-09-23 15:19 UTC (permalink / raw)



"Hyman Rosen" <hyrosen@mail.com> wrote in message
news:1032789075.864322@master.nyc.kbcfp.com...
> tmoran@acm.org wrote:
> And further yet, why do you think you get to rewrite the
> given requirements just because they don't suit the style of
> your favorite programming language?
>

hmm... I don't think Tom's is advocating that requirements should be
rewritten to accommodate a programming language.  I believe he was stating
that sometimes it is valid to rewrite requirements given known constraints
of the problem.

-CRM





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

* Re: Beginer problem: variable array size
  2002-09-23 15:19               ` Chad R. Meiners
@ 2002-09-23 16:00                 ` Hyman Rosen
  0 siblings, 0 replies; 62+ messages in thread
From: Hyman Rosen @ 2002-09-23 16:00 UTC (permalink / raw)


Chad R. Meiners wrote:
> I believe he was stating that sometimes it is valid
 > to rewrite requirements given known constraints
> of the problem.

Well, in this particular case, it's the professor looking
at the program and giving you a failing grade for having
a fixed limit when explictly told not to do that.




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

* Re: Beginer problem: variable array size
  2002-09-23 13:53             ` Hyman Rosen
  2002-09-23 15:19               ` Chad R. Meiners
@ 2002-09-23 17:09               ` tmoran
  2002-09-23 18:18                 ` Hyman Rosen
  2002-09-23 20:10                 ` Dennis Lee Bieber
  2002-09-24 12:36               ` Marin David Condic
  2 siblings, 2 replies; 62+ messages in thread
From: tmoran @ 2002-09-23 17:09 UTC (permalink / raw)


> The professor probably has files of input numbers that will
> be fed to each submitted program. I'll bet one of them is
> very large, to test the input size limit even if the sort
> won't complete in a reasonable amount of time.
  I'd be very interested in seeing an answer to the OP problem that had no
limit on the number of inputs.  I'd even be interested in a version that
would run with a very large number, say 6E23, of inputs.  Would it use all
the machines on the internet to store input?  I fear even that wouldn't be
enough.  If you can't show such a program, then I'd like to know what in
fact are its limits, either as a constant like 8*3600 or 10_000_000
or by a formula like "System_RAM_In_Bytes/2" or some such thing.

> Furthermore, if you are going to have an arbitrary limit,
> you have to provide the extra code to handle the case of
> the limit being exceeded.
  Not for an introductory class.  And for a more advanced class,
I suspect a "raised Storage_Error" message, or taking a year to run,
wouldn't receive a very high grade.

> And further yet, why do you think you get to rewrite the
> given requirements just because they don't suit the style of
  The OP problem spec was incomplete.  Given that it followed a Hello
World program, I suspect it came early in a programming class and the prof
would be happy with a quadratic sort and would test it with a few tens at
most of inputs.  If it was my homework, I'd include a statement of that
assumption and why I made it.  If the assignment came up in an advanced
class after the prof had been describing a space probe crashing into the
sun, collecting a measurement every 50 nanoseconds for one half second,
then sorting and transmitting those 10 million measurements in the
remaining half second before meltdown, I would make different
assumptions, document them, and write the program a different way.

  It's bad to make foolishly limiting assumptions, but worse to
depend on undocumented assumptions.  Just the act of documenting
them may encourage a programmer to Think! and make better assumptions.



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

* Re: Beginer problem: variable array size
  2002-09-23 17:09               ` tmoran
@ 2002-09-23 18:18                 ` Hyman Rosen
  2002-09-23 19:53                   ` tmoran
  2002-09-23 20:10                 ` Dennis Lee Bieber
  1 sibling, 1 reply; 62+ messages in thread
From: Hyman Rosen @ 2002-09-23 18:18 UTC (permalink / raw)


tmoran@acm.org wrote:
 > If you can't show such a program, then I'd like to know what in
> fact are its limits, either as a constant like 8*3600 or 10_000_000
> or by a formula like "System_RAM_In_Bytes/2" or some such thing.

How very odd. You yourself posted a program which meets the OP's
requirements. In the terms you describe above, can you tell me
what the limits are of your program?

There is a fundamental difference between a program which has a
wired-in size limit and a program which is bound by available
memory, or even available address space. For one thing, when the
latter program is moved to a system with more resources, it will
hndle larger inputs. The former program will be stuck at its limit
until it's revised.

My former office mate held by the rule of "zero, one, or infinity"
when it came to allowable limits. I have seen this rule violated
to much distress. The latest example occurred just weeks ago, when
the risk management system we use was discovered to have a hard
limit of one hundred different security types.




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

* Re: Beginer problem: variable array size
  2002-09-23 18:18                 ` Hyman Rosen
@ 2002-09-23 19:53                   ` tmoran
  2002-09-23 20:32                     ` Hyman Rosen
  0 siblings, 1 reply; 62+ messages in thread
From: tmoran @ 2002-09-23 19:53 UTC (permalink / raw)


>How very odd. You yourself posted a program which meets the OP's requirements.
  I lied.  He might accept it, but it doesn't actually meet the stated spec.
Of course no program could meet that spec.

>In the terms you describe above, can you tell me what the limits are
>of your program?
>> type List_Type is array (Integer range <>) of Integer;
  Clearly has a limit of Integer'range inputs.  If Integer'size = 16,
that's 65,536 inputs (if I understand correctly the rules for the lower
bound of a concatenation).  If Integer'size = 32, there's probably a limit
much smaller than 2**32 set by recursion stack growth.  I can't tell you
accurately what that might be without finding out more about how the stack
is used by the program as compiled on a particular system.
  The program used a quadratic sort.  Since it prints during the sort,
you could probably have a good size input before there was a noticeable,
non-IO, delay, but that would happen even on a reasonably fast (ca 2002)
machine when you got into a few million inputs.
  The lack of a literal number, or a comment saying the above, means
the limit is hidden from a quick scan - but there is a limit.

> There is a fundamental difference between a program which has a
> wired-in size limit and a program which is bound by available
> memory, or even available address space. For one thing, when the
> latter program is moved to a system with more resources, it will
> hndle larger inputs. The former program will be stuck at its limit
> until it's revised.
  I agree there's a big difference between a program with a literal
numeric constant as a limit and a program that adapts to the resources
available, and the latter is normally better.  But the former at least
documents clearly what the limit is.  The adaptable program should say
what its limits are, or how to calculate those limits on a particular
machine.  How often have you seen that, vs leaving it to experiment and
Constraint_Error or Storage_Error or "CPU time exceeded"?  It's like
failing to do error analysis for a numeric program, or using type Integer
rather than an explicitly declared type.  The sloppy approach is commonly
done (I don't claim purity myself), but it shouldn't be encouraged.



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

* Re: Beginer problem: variable array size
  2002-09-23 17:09               ` tmoran
  2002-09-23 18:18                 ` Hyman Rosen
@ 2002-09-23 20:10                 ` Dennis Lee Bieber
  2002-09-23 23:09                   ` tmoran
  1 sibling, 1 reply; 62+ messages in thread
From: Dennis Lee Bieber @ 2002-09-23 20:10 UTC (permalink / raw)


tmoran@acm.org fed this fish to the penguins on Monday 23 September 
2002 10:09 am:

>
> assumption and why I made it.  If the assignment came up in an
> advanced class after the prof had been describing a space probe
> crashing into the sun, collecting a measurement every 50 nanoseconds
> for one half second, then sorting and transmitting those 10 million
> measurements in the remaining half second before meltdown, I would
> make different assumptions, document them, and write the program a
> different way.
> 
        Granted, this comes after 20 years in the industry (and maybe no more 
-- I was laid-off <G>)...

        Given your description as the requirements I'd have to argue at a 
design review that it would be more efficient to have the probe NOT 
sort the measurements, instead using the time wasted on sorting to 
collect even MORE data measurements and send the whole batch in a 
continuous stream -- leave the sorting to the ground station post 
processing, wherein any delay is not critical.

--
 > ============================================================== <
 >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed@dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



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

* Re: Beginer problem: variable array size
  2002-09-23 19:53                   ` tmoran
@ 2002-09-23 20:32                     ` Hyman Rosen
  0 siblings, 0 replies; 62+ messages in thread
From: Hyman Rosen @ 2002-09-23 20:32 UTC (permalink / raw)


tmoran@acm.org wrote:
>   I agree there's a big difference between a program with a literal
> numeric constant as a limit and a program that adapts to the resources
> available, and the latter is normally better.  But the former at least
> documents clearly what the limit is.

Does it really? That may be the case for the toy program presented
here. But what happens when this style of programming is used as a
piece of a large project? If the buffer overlow problems so often
reported have taught us anything, it's that programmers guess sizes
incorrectly. Of course an Ada program wouldn't actually overflow its
buffers, but it would fail to process its input correctly - either by
ignoring some of it, or by reporting errors and not processing it at
all.




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

* Re: Beginer problem: variable array size
  2002-09-23 20:10                 ` Dennis Lee Bieber
@ 2002-09-23 23:09                   ` tmoran
  2002-09-24  2:33                     ` Dennis Lee Bieber
  0 siblings, 1 reply; 62+ messages in thread
From: tmoran @ 2002-09-23 23:09 UTC (permalink / raw)


> Given your description as the requirements I'd have to argue at a
> design review that it would be more efficient to have the probe NOT
> sort the measurements, instead ...
This being an imaginary homework assignment, and thus two steps away from
reality, let me suppose you really don't know exactly when the system will
meltdown, so there is a strong possibility not all data can be sent.
Further suppose it's most important to find out the largest values
measured, and the distribution, so if any data is to be lost, it should be
the small values.  A radix sort/histogram would do the job nicely.



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

* Re: Beginer problem: variable array size
  2002-09-23 23:09                   ` tmoran
@ 2002-09-24  2:33                     ` Dennis Lee Bieber
  0 siblings, 0 replies; 62+ messages in thread
From: Dennis Lee Bieber @ 2002-09-24  2:33 UTC (permalink / raw)


tmoran@acm.org fed this fish to the penguins on Monday 23 September 
2002 04:09 pm:

>> Given your description as the requirements I'd have to argue at a
>> design review that it would be more efficient to have the probe NOT
>> sort the measurements, instead ...
> This being an imaginary homework assignment, and thus two steps away
> from reality, let me suppose you really don't know exactly when the
> system will meltdown, so there is a strong possibility not all data
> can be sent. Further suppose it's most important to find out the
> largest values measured, and the distribution, so if any data is to be
> lost, it should be
> the small values.  A radix sort/histogram would do the job nicely.

        That's even more a case for continuous streaming of measurements... As 
long as the transmitter is active the ground station is getting 
measurements. No loss of any up to the moment the transmitter fails. If 
the largest value came early in the stream, no problem... If it was the 
last value before meltdown you'd still get it... <G>

-- 
--
 > ============================================================== <
 >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed@dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



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

* Re: Beginer problem: variable array size
  2002-09-23 13:53             ` Hyman Rosen
  2002-09-23 15:19               ` Chad R. Meiners
  2002-09-23 17:09               ` tmoran
@ 2002-09-24 12:36               ` Marin David Condic
  2 siblings, 0 replies; 62+ messages in thread
From: Marin David Condic @ 2002-09-24 12:36 UTC (permalink / raw)


Not being able to speak for the prof in question, of course, but one must
ask what the point of the exercise is. A "Hello World!" app is to get you to
figure out how to run the compiler, etc. A "Read a bunch of numbers and sort
them" exercise is probably there to teach you how to write a sort. Getting
bogged down in side issues like how to properly design the input so that no
ingenious and abusive user can possibly cause it to crash is *probably* not
the point of the exercise. In a class on abstract data types, etc. I might
give an assignment with the objective being "Learn how to use dynamic
allocation and the creation of linked lists" - but then it would be cheating
to say "Well, the language already gives it to me, so I'll use that..."

I just don't think that a case can be made that putting some kind of
arbitrary limit on input for a student exercise because the language doesn't
give you a convenient, easy way of otherwise handling it is a bad thing.
It's a _student_exercise_ - not a production piece of code.

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================
Hyman Rosen <hyrosen@mail.com> wrote in message
news:1032789075.864322@master.nyc.kbcfp.com...
>
> In modern computing environments, programs that take input
> from the user are easily hooked up to take input from other
> programs or files instead, so working on the assumption that
> the program will be used only by a human typist is foolish.
> The professor probably has files of input numbers that will
> be fed to each submitted program. I'll bet one of them is
> very large, to test the input size limit even if the sort
> won't complete in a reasonable amount of time.
>
> Furthermore, if you are going to have an arbitrary limit,
> you have to provide the extra code to handle the case of
> the limit being exceeded. I suppose you could just range
> over the size of the array and ignore any extra input. This
> is exactly the kind of silently wrong behavior I was talking
> about.
>
> And further yet, why do you think you get to rewrite the
> given requirements just because they don't suit the style of
> your favorite programming language?
>





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

* Re: Beginer problem: variable array size
  2002-09-20 16:31               ` Warren W. Gay VE3WWG
@ 2002-09-24 12:41                 ` Thomas Dickey
  0 siblings, 0 replies; 62+ messages in thread
From: Thomas Dickey @ 2002-09-24 12:41 UTC (permalink / raw)


Warren W. Gay VE3WWG <ve3wwg@cogeco.ca> wrote:

> I remember hitting line length limits on SCO UNIX's _xterm_
> sessions. Grrrr.

perhaps this:
around 200 characters (a fixed-size buffer used for the alternate screen).

I fixed that in XFree86 xterm several years ago.

-- 
Thomas E. Dickey <dickey@radix.net> <dickey@herndon4.his.com>
http://dickey.his.com
ftp://dickey.his.com



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

* Re: Beginer problem: variable array size
  2002-09-22 13:18             ` Marin David Condic
@ 2002-09-24 16:55               ` Warren W. Gay VE3WWG
  2002-09-25 12:06                 ` Marin David Condic
  0 siblings, 1 reply; 62+ messages in thread
From: Warren W. Gay VE3WWG @ 2002-09-24 16:55 UTC (permalink / raw)


Marin David Condic wrote:
...
> If eventually something gets into the ARM as a standard library, that's
> great. But I think it would be better to get something general-purpose
> accepted as a semi-standard in a faster and more flexible manner. Get a
> container library out there that is generally accepted as the official Ada
> library and start experimenting with it. In a year or so, you'll know what
> its weaknesses are and another cut can be made at it. Soon enough you'll
> have a stable version that may satisfy 80% of the user's needs. 

I agree, though I admit that I am biased (for the general purpose use).

I know this has been discussed before (but perhaps not enough),
doesn't the Booch components more or less fit this "first stage"?  From
my point of view, the # 1 disadvantage of the booch components is just
getting them properly instatiated. Apart from realtime issues, what other
issues exist?
-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




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

* Re: Beginer problem: variable array size
  2002-09-24 16:55               ` Warren W. Gay VE3WWG
@ 2002-09-25 12:06                 ` Marin David Condic
  0 siblings, 0 replies; 62+ messages in thread
From: Marin David Condic @ 2002-09-25 12:06 UTC (permalink / raw)


I don't know that they won't meet realtime requirements. I wouldn't worry
too much about that anyway. Realtime is only a fraction of the Ada users and
probably not so large a voting block that they need to be catered to in
every instance. If the library is unsuitable for realtime, they're in the
same boat they are in now - roll your own. (Given the mindset of many
realtime guys, we'd probably go off and do that anyway because we didn't
invent it and we want the devil we know! :-)

I think the issue was one of complexity - many thought Booch was just too
hard to understand or use in things like student applications. Maybe. Maybe
not. I think it would be better to adopt *something* rather than stand
around arguing about it for the next 10 years while C++ goes and wins
converts to the STL. You either meet the market's needs or they go somewhere
else. If other languages provide large libraries of useful stuff and Ada
doesn't - too bad for Ada. The market will be happy to use something else.
Its Darwin at work. Adapt - or else! (What are the odds of Ada succeeding in
getting a Darwin Award here? :-)

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Warren W. Gay VE3WWG <ve3wwg@cogeco.ca> wrote in message
news:3D90991E.9040205@cogeco.ca...
>
> I agree, though I admit that I am biased (for the general purpose use).
>
> I know this has been discussed before (but perhaps not enough),
> doesn't the Booch components more or less fit this "first stage"?  From
> my point of view, the # 1 disadvantage of the booch components is just
> getting them properly instatiated. Apart from realtime issues, what other
> issues exist?






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

* Re: Beginer problem: variable array size
  2002-09-22 13:00               ` Marin David Condic
@ 2002-09-26  3:37                 ` Kevin Cline
  2002-09-26 12:42                   ` Marin David Condic
  0 siblings, 1 reply; 62+ messages in thread
From: Kevin Cline @ 2002-09-26  3:37 UTC (permalink / raw)


"Marin David Condic" <mcondic.auntie.spam@acm.org> wrote in message news:<amkeud$haj$1@slb3.atl.mindspring.net>...
> Well, as is often the case, the answer is "It Depends". Yes, there are a
> number of cases where you don't want to set arbitrary limits on data volume.
> Usually, these are of significant enough importance, that going to the
> trouble of developing a proper data structure to hold it is not that big a
> deal in the grand scheme of things. However, when you're confronted with a
> student project or some light-duty, quick and dirty app that reasonably
> approximates the case described earlier (punching in a bunch of numbers to
> sort...) Its typically not that big a deal to impose some arbitrary (and
> large) upper limit if it allows you simplicity of implementation. 

That's great, but it doesn't teach students to produce useful programs.
CS graduates need considerable experience using appropriate data structures.
One class in data structures and algorithms is not enough.



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

* Re: Beginer problem: variable array size
  2002-09-26  3:37                 ` Kevin Cline
@ 2002-09-26 12:42                   ` Marin David Condic
  0 siblings, 0 replies; 62+ messages in thread
From: Marin David Condic @ 2002-09-26 12:42 UTC (permalink / raw)


Do you expect to teach a student all of computer science in one assignment?
:-) My point was that given some beginning level assignment ("Read in a
bunch of numbers and sort them") I wouldn't find it necessary to add some
additional requirement ("Don't create an artificial limit on input" -
Although Tom Moran will observe that there always *is* a limit :-) to
somehow or other make the exercise more valuable. If the language doesn't
make that a trivial thing to do (perhaps because its arrays are naturally
dynamic) then why add it to the assignment?

The point of the exercise is probably to teach the student how to use the
I/O of the language and give them some experience with sorting numbers. Do
they *really* need to become human/machine interface experts on their second
assignment? Probably not. Save *that* lesson for one of the more advanced
courses - or at least until they've written a few more basic programs. And,
no, I don't think students should only have one class in data structures and
algorithms and never said that. Remember that the original illustration was
given as a "typical" second programming assignment for a beginning student.
At that level - and probably for many other levels of student assignments -
its completely fair to artificially limit the problem so that the student
spends his time focusing on the thing the assignment is supposed to
illustrate rather than get him wrapped up in all sorts of side issues that
expand the scope and make the job needlessly harder. Students are, after
all, pressed for time and have other classes besides just this one beginning
CS course, right? Have a little mercy on them. :-)

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Kevin Cline <kcline17@hotmail.com> wrote in message
news:ba162549.0209251937.5b4b8cef@posting.google.com...
>
> That's great, but it doesn't teach students to produce useful programs.
> CS graduates need considerable experience using appropriate data
structures.
> One class in data structures and algorithms is not enough.





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

* Re: Beginer problem: variable array size
  2002-09-15 14:53 Beginer problem: variable array size Nacho
  2002-09-15 16:45 ` Larry Kilgallen
  2002-09-17 10:20 ` Georg Bauhaus
@ 2002-10-02 15:04 ` Matthew Heaney
  2002-10-02 16:26   ` Preben Randhol
  2 siblings, 1 reply; 62+ messages in thread
From: Matthew Heaney @ 2002-10-02 15:04 UTC (permalink / raw)



"Nacho" <NACHANGA@terra.es> wrote in message
news:am26u4$d2q$1@nsnmpen2-gest.nuria.telefonica-data.net...
> I am learning ada and i have to implement an array of unknown size until
> rutime.
> The array must be resizable at runtime. This is easy to achieve for me in
> other lenguajes like c++, but i am new to ada and i don't know hot to
> resolve the problem. The solution in c++ code could be:
[snipped]
> How can I do the same in ada?
> How can I use dinamics arrays of variable size in ada?

The Charles container library comes with a vector data structure that does
this sort of thing, e.g.

package Integer_Vectors is new Charles.Vectors.Unbounded (Integer);
subtype Vector_Subtype is Integer_Vectors.Container_Type;
use Integer_Vectors;

V : Vector_Subtype := To_Container (Length => 50);
...
V := To_Container (Length => 80);
--or--
Assign (V, Length => 80);

If you're comfortable with the C++ STL, then using Charles will be natural.

http://home.earthlink.net/~matthewjheaney/charles/index.html

There's also a deque container type, which allows insertions at the front of
the container.






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

* Re: Beginer problem: variable array size
  2002-09-18 11:53       ` Marin David Condic
@ 2002-10-02 15:08         ` Matthew Heaney
  2002-10-03 12:17           ` Marin David Condic
  0 siblings, 1 reply; 62+ messages in thread
From: Matthew Heaney @ 2002-10-02 15:08 UTC (permalink / raw)



"Marin David Condic" <mcondic.auntie.spam@acm.org> wrote in message
news:amcako$bbg$1@slb7.atl.mindspring.net...
> Sometimes people like to use arrays as if they were lists. Ada doesn't
have
> a standard list type, so there's no pointing them in that direction.
Dynamic
> arrays exist in some languages - just not in Ada. (Well, O.K.
> Unbounded_String, but that's not a general array type.) The good news is
> that neither does C, so in either language, the OP would have to go about
> creating his own construct. Maybe C++ has a dynamic array class?

The Charles container library has both doubly-linked and singly-linked
container types.  It also has a vector, which is a "dynamic array."
(There's also a deque, with slightly different semantics.)

http://home.earthlink.net/~matthewjheaney/charles/index.html

Perhaps these can be of some use.







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

* Re: Beginer problem: variable array size
  2002-09-19  0:43     ` Robert A Duff
                         ` (2 preceding siblings ...)
  2002-09-20  3:06       ` Munch
@ 2002-10-02 15:13       ` Matthew Heaney
  3 siblings, 0 replies; 62+ messages in thread
From: Matthew Heaney @ 2002-10-02 15:13 UTC (permalink / raw)



"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message
news:wccd6ran71c.fsf@shell01.TheWorld.com...
>
> It's usually better to allocate exponentially-more space each time a
> reallocate-and-copy is needed.

The C++ STL and Ada95 Charles libraries both work by multiplying the current
length of the underlying array by a factor of 2, and using that as the
length of the new internal array when reallocating.

http://home.earthlink.net/~matthewjheaney/charles/index.html

In Charles, Size returns the length of the internal array, and Resize can be
used to set the value explicitly.  (These are exactly equivalent to the
Capacity and Reserve member functions of the STL vector class.)







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

* Re: Beginer problem: variable array size
  2002-10-02 15:04 ` Matthew Heaney
@ 2002-10-02 16:26   ` Preben Randhol
  2002-10-02 19:53     ` Matthew Heaney
  2002-10-22 14:11     ` Matthew Heaney
  0 siblings, 2 replies; 62+ messages in thread
From: Preben Randhol @ 2002-10-02 16:26 UTC (permalink / raw)


On Wed, 2 Oct 2002 11:04:04 -0400, Matthew Heaney wrote:
> 
> If you're comfortable with the C++ STL, then using Charles will be natural.

I'm not :-) so I'm wondering which documents that are best to read in
order to use charles?

Preben
-- 
Ada95 is good for you.
http://libre.act-europe.fr/Software_Matters/02-C_pitfalls.pdf



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

* Re: Beginer problem: variable array size
  2002-10-02 16:26   ` Preben Randhol
@ 2002-10-02 19:53     ` Matthew Heaney
  2002-10-03 12:31       ` Marin David Condic
  2002-10-22 14:11     ` Matthew Heaney
  1 sibling, 1 reply; 62+ messages in thread
From: Matthew Heaney @ 2002-10-02 19:53 UTC (permalink / raw)



"Preben Randhol" <randhol+news@pvv.org> wrote in message
news:slrnapm7gv.2r7.randhol+news@kiuk0156.chembio.ntnu.no...
> On Wed, 2 Oct 2002 11:04:04 -0400, Matthew Heaney wrote:
> >
> > If you're comfortable with the C++ STL, then using Charles will be
natural.
>
> I'm not :-) so I'm wondering which documents that are best to read in
> order to use charles?

Any book on the STL will do.  Try

STL Tutorial and Reference, 2nd ed
Musser, Derge, Saini

Or you could just go to the SGI website:

http://www.sgi.com/tech/stl/








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

* Re: Beginer problem: variable array size
  2002-10-02 15:08         ` Matthew Heaney
@ 2002-10-03 12:17           ` Marin David Condic
  0 siblings, 0 replies; 62+ messages in thread
From: Marin David Condic @ 2002-10-03 12:17 UTC (permalink / raw)


Probably a good alternative for someone doing serious development. Better to
use this (or one of the other available libraries) rather than build it from
bottom-dead-center. However, IIRC, this was a student project and it is
usually not considered kosher to hand in other people's code.

Although what if there was an Ada textbook that supplied a library like this
on a CD and taught Ada with the presumption of available containers such as
this..... Hmmm.... Might that help make a de facto standard?

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Matthew Heaney <mheaney@on2.com> wrote in message
news:upm2vueotr4p1b@corp.supernews.com...
>
> "Marin David Condic" <mcondic.auntie.spam@acm.org> wrote in message
> news:amcako$bbg$1@slb7.atl.mindspring.net...
>
> The Charles container library has both doubly-linked and singly-linked
> container types.  It also has a vector, which is a "dynamic array."
> (There's also a deque, with slightly different semantics.)
>
> http://home.earthlink.net/~matthewjheaney/charles/index.html
>
> Perhaps these can be of some use.
>
>
>
>





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

* Re: Beginer problem: variable array size
  2002-10-02 19:53     ` Matthew Heaney
@ 2002-10-03 12:31       ` Marin David Condic
  2002-10-03 15:15         ` Matthew Heaney
  0 siblings, 1 reply; 62+ messages in thread
From: Marin David Condic @ 2002-10-03 12:31 UTC (permalink / raw)


That might be a reasonable answer short-term, but long range, if you ask
folks to go read a book on STL, the attitude might become: "If I've got to
learn STL first in order to use this library then why not just use STL and
save myself the extra trouble?" This, by the way, is the same problem people
have when we Ada-philes suggest "Oh, but you can always bind to that C
library...." Its extra work and extra problems that the end user just
doesn't want to own.

I'm sure you've got a fine library here and I'm suggesting that if you take
some time to write even a cursory user's manual, that will help make it its
own thing rather than a "me too" venture.

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Matthew Heaney <mheaney@on2.com> wrote in message
news:upmjlen322hcd@corp.supernews.com...
>
> Any book on the STL will do.  Try
>
> STL Tutorial and Reference, 2nd ed
> Musser, Derge, Saini
>
> Or you could just go to the SGI website:
>
> http://www.sgi.com/tech/stl/
>
>
>
>
>





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

* Re: Beginer problem: variable array size
  2002-10-03 12:31       ` Marin David Condic
@ 2002-10-03 15:15         ` Matthew Heaney
  2002-10-21 23:38           ` Matthew Heaney
  0 siblings, 1 reply; 62+ messages in thread
From: Matthew Heaney @ 2002-10-03 15:15 UTC (permalink / raw)



"Marin David Condic" <mcondic.auntie.spam@acm.org> wrote in message
news:anhdd5$bl4$1@nntp9.atl.mindspring.net...
>
> I'm sure you've got a fine library here and I'm suggesting that if you
take
> some time to write even a cursory user's manual, that will help make it
its
> own thing rather than a "me too" venture.

OK.  I'll give myself the task of writing a manual.  Actually, a readme
might be enough to get started.

Thanks for the advice,
Matt






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

* Re: Beginer problem: variable array size
  2002-10-03 15:15         ` Matthew Heaney
@ 2002-10-21 23:38           ` Matthew Heaney
  0 siblings, 0 replies; 62+ messages in thread
From: Matthew Heaney @ 2002-10-21 23:38 UTC (permalink / raw)


"Matthew Heaney" <mheaney@on2.com> wrote in message news:<upono9in57tv7e@corp.supernews.com>...
>
> "Marin David Condic" <mcondic.auntie.spam@acm.org> wrote in message
> news:anhdd5$bl4$1@nntp9.atl.mindspring.net...
> >
> > I'm sure you've got a fine library here and I'm suggesting that if you take
> > some time to write even a cursory user's manual, that will help make it
> > its own thing rather than a "me too" venture.
> 
> OK.  I'll give myself the task of writing a manual.  Actually, a readme
> might be enough to get started.

I have written documentation for the unbounded vector container, which
is posted online at my web site.

http://home.earthlink.net/~matthewjheaney/charles/charles-vectors-unbounded.html

I have also released a new version (20021021) of the Charles library,
which includes the changes to the vector package.

http://home.earthlink.net/~matthewjheaney/charles/index.html

Let me know if this documentation is what you had in mind.

Matt



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

* Re: Beginer problem: variable array size
  2002-10-02 16:26   ` Preben Randhol
  2002-10-02 19:53     ` Matthew Heaney
@ 2002-10-22 14:11     ` Matthew Heaney
  1 sibling, 0 replies; 62+ messages in thread
From: Matthew Heaney @ 2002-10-22 14:11 UTC (permalink / raw)


Preben Randhol <randhol+news@pvv.org> wrote in message news:<slrnapm7gv.2r7.randhol+news@kiuk0156.chembio.ntnu.no>...
> On Wed, 2 Oct 2002 11:04:04 -0400, Matthew Heaney wrote:
> > 
> > If you're comfortable with the C++ STL, then using Charles will be natural.
> 
> I'm not :-) so I'm wondering which documents that are best to read in
> order to use charles?

I have written documentation for the vector container, which is both a
tutorial and a reference manual.  You may be able to use this to get
started.

http://home.earthlink.net/~matthewjheaney/charles/charles-vectors-unbounded.html

There's also a new release (20021021) of the library, containing
changes to the vector package.

http://home.earthlink.net/~matthewjheaney/charles/index.html

Drop me a line to let me know whether the documentation is adequate.

Matt



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

end of thread, other threads:[~2002-10-22 14:11 UTC | newest]

Thread overview: 62+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-15 14:53 Beginer problem: variable array size Nacho
2002-09-15 16:45 ` Larry Kilgallen
2002-09-15 16:16   ` Nacho
2002-09-15 16:26     ` Ludovic Brenta
2002-09-15 17:46     ` Jeffrey Carter
2002-09-15 18:27     ` Pascal Obry
2002-09-15 20:03     ` Larry Kilgallen
2002-09-17 14:22     ` Ted Dennison
2002-09-18 11:53       ` Marin David Condic
2002-10-02 15:08         ` Matthew Heaney
2002-10-03 12:17           ` Marin David Condic
2002-09-19  0:43     ` Robert A Duff
2002-09-19  1:25       ` Jeffrey Carter
2002-09-19 14:17       ` Hyman Rosen
2002-09-20  3:06       ` Munch
2002-09-20  4:49         ` Jim Rogers
2002-09-20  6:35         ` tmoran
2002-09-20 16:00           ` Pat Rogers
2002-09-20 16:07             ` Preben Randhol
2002-09-20 20:15               ` Pat Rogers
2002-09-20 12:11         ` Marin David Condic
2002-09-20 13:59           ` Larry Kilgallen
2002-09-20 14:55             ` Hyman Rosen
2002-09-20 16:10               ` Larry Kilgallen
2002-09-20 16:31               ` Warren W. Gay VE3WWG
2002-09-24 12:41                 ` Thomas Dickey
2002-09-21 10:44               ` Thomas Dickey
2002-09-23 13:37                 ` Hyman Rosen
2002-09-22 13:00               ` Marin David Condic
2002-09-26  3:37                 ` Kevin Cline
2002-09-26 12:42                   ` Marin David Condic
2002-09-22 12:49             ` Marin David Condic
2002-09-20 16:28           ` Warren W. Gay VE3WWG
2002-09-20 17:49             ` Hyman Rosen
2002-09-21  7:30               ` Preben Randhol
2002-09-23 13:41                 ` Hyman Rosen
2002-09-22  3:34               ` Ted Dennison
2002-09-22 13:18             ` Marin David Condic
2002-09-24 16:55               ` Warren W. Gay VE3WWG
2002-09-25 12:06                 ` Marin David Condic
2002-09-21 22:23           ` tmoran
2002-09-23 13:53             ` Hyman Rosen
2002-09-23 15:19               ` Chad R. Meiners
2002-09-23 16:00                 ` Hyman Rosen
2002-09-23 17:09               ` tmoran
2002-09-23 18:18                 ` Hyman Rosen
2002-09-23 19:53                   ` tmoran
2002-09-23 20:32                     ` Hyman Rosen
2002-09-23 20:10                 ` Dennis Lee Bieber
2002-09-23 23:09                   ` tmoran
2002-09-24  2:33                     ` Dennis Lee Bieber
2002-09-24 12:36               ` Marin David Condic
2002-10-02 15:13       ` Matthew Heaney
2002-09-19 20:25     ` Brian Gaffney
2002-09-17 10:20 ` Georg Bauhaus
2002-10-02 15:04 ` Matthew Heaney
2002-10-02 16:26   ` Preben Randhol
2002-10-02 19:53     ` Matthew Heaney
2002-10-03 12:31       ` Marin David Condic
2002-10-03 15:15         ` Matthew Heaney
2002-10-21 23:38           ` Matthew Heaney
2002-10-22 14:11     ` Matthew Heaney

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