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.
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.
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" <Kilg...@SpamCop.net> escribió en el mensaje
news:HFiRcR...@eisner.encompasserve.org...
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.
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
> 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
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.
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
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.
> 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
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."
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 <denn...@telepath.com> wrote in message
news:4519e058.02091...@posting.google.com...
>
> Why?
>
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.
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.
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*
>
> 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
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;
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 <ram...@sigecom.net> wrote in message
news:38993b18.0209...@posting.google.com...
> 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 :-)
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.
> 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 !
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
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
I remember hitting line length limits on SCO UNIX's _xterm_
sessions. Grrrr.
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.
Ah yes, right. Thanks!
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
> 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 <dic...@radix.net> <dic...@herndon4.his.com>
http://dickey.his.com
ftp://dickey.his.com
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.
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 <Kilg...@SpamCop.net> wrote in message
news:qhGf3v...@eisner.encompasserve.org...
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 <hyr...@mail.com> wrote in message
news:10325335...@master.nyc.kbcfp.com...
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 <ve3...@cogeco.ca> wrote in message
news:3D8B4CC9...@cogeco.ca...
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.
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...
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?
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
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.
> 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.
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.
>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.
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.
>
> 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.
--
> ============================================================== <
> wlf...@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulf...@dm.net | Bestiaria Support Staff <
> ============================================================== <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <
> 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.
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 <hyr...@mail.com> wrote in message
news:10327890...@master.nyc.kbcfp.com...
>
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?
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>
--
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 <ve3...@cogeco.ca> wrote in message
news:3D90991E...@cogeco.ca...
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.
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 <kcli...@hotmail.com> wrote in message
news:ba162549.02092...@posting.google.com...
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.
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.
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.)
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
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:
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 <mhe...@on2.com> wrote in message
news:upm2vue...@corp.supernews.com...
>
> "Marin David Condic" <mcondic.a...@acm.org> wrote in message
> news:amcako$bbg$1...@slb7.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.
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 <mhe...@on2.com> wrote in message
news:upmjle...@corp.supernews.com...
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
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
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