From: brett on
Thank you all for your very useful information, Thomas Locke's full example
of Barnes code was extremely helpful. Which I dropped into GNAT for testing.

I was having problems resolving the what? packages I needed to be able to process bounded strings, I'd already sucessfully written a Unbounded strings program and could not see why Bounded strings were causing me so many problems !
The need for "Generic_Bounded_Length" part was very unclear, and hoe it related to the rest of my code.

BTW: John Barnes Ada 2005 Book is truly excellent, however I think I also need a more "Practical Ada 2005 Programming" book as well. The titles I see on Internet book sellers are mainly Ada95 and I'm unsure if they have any relevance to learning Ada 2005. Any Suggestions ??



My finished test program is :

-- brett hallett : 18/10/2010
-- testing --redefined Integer type Temp_Int
--Bounded String type
with Ada.Strings.Bounded; use Ada.Strings.Bounded;
with Ada.Text_IO.Bounded_IO;

procedure calctemp4 is
use Ada.Strings.Bounded;
use Ada.Text_IO;

subtype Temp_Int is integer range 50 .. 350 ;

package BS is new Generic_Bounded_Length(30); use BS;
-- define the 'base' string to work with
package BS_IO is new Bounded_IO ( BS ); use BS_IO;

strline : BS.Bounded_String := (BS.Max_Length * " ");
-- create & initialize strline to spaces

C : Temp_Int := Temp_Int'First; -- start temperature
F : Integer;

function convert ( X : Integer ) return Integer is
F : Integer;
begin
F := (( X * 9 )/ 5 ) +32; -- standard C to F calc
return F;
end convert;

begin

put_line("calctemp");
put(" Celsius Farhenheit"); new_line;

while C < Temp_Int'Last loop -- loop in range

BS.overwrite(strline, 1, c'img);
f := convert(c);
BS.overwrite(strLine, 10, f'img);
BS_IO.Put_line(strline);
C := C + 25;
strline := BS.Max_Length * "*";
-- 'clear' strline ( not necessary , just testing :-)
end loop;
put(" -- finished--"); new_line;
end calctemp4;




---
frmsrcurl: http://compgroups.net/comp.lang.ada/confusion-with-string-initialization
From: Alex Mentis on
> BTW: John Barnes Ada 2005 Book is truly excellent, however I think I also need a more
> "Practical Ada 2005 Programming" book as well. The titles I see on Internet book sellers
> are mainly Ada95 and I'm unsure if they have any relevance to learning Ada 2005. Any
> Suggestions ??

The Barnes book is one-stop shopping for a comprehensive text that is
a half-step easier to read than the ARM. It's an Ada "bible" that
every serious Ada programmer should have on their shelf, but I would
never give it to a novice programmer to learn from. It doesn't appear
to be intended for that. I often lament the availability of good
beginner books that cover the new features in Ada 2005.

If you just want to learn the essential basics of procedural
programming in Ada, then the Ada 95 text offerings out there are
(mostly) equally applicable to Ada 2005. Two good introductory books
are _Ada 95: Problem Solving and Program Design_, 3rd ed. by Feldman
and Koffman and _Programming and Problem Solving with Ada 95_, 2nd ed.
by Dale, Weems, and McCormick. I personally like the sequential
progression and explanation style in Dale better, but the Feldman text
is a bit more comprehensive, getting into more advanced topics like
variant records, generics (templates), access types (pointers) and
tasks. A good (and free) book you can find online is _Ada 95: The
Craft of Object-Oriented Programming_ by John English. I'd put it
between Dale and Feldman - English covers more advanced topics than
Dale, but it's laid out a bit more clearly than Feldman. Plus, it's
free, so you should definitely at least get that.

At an intermediate level, or as a supplemental text to those above,
one of my personal frequently-used books is _Rendezvous With Ada 95_,
2nd ed. by Naiditch. This book goes into much further detail than the
ones above on generics, exceptions, access types, input/output, and
tasks. It also adds a section on low-level programming and
representation clauses.

The English, Naiditch, and Feldman texts all cover object-oriented
programming for Ada 95, but if you want to learn OO in Ada 2005, skip
these sections and buy _Ada Plus Data Structures: An Object Oriented
Approach_, 2nd ed by Dale and McCormick. This text covers the updated
object oriented features of Ada 2005 and picks up where _Programming
and Problem Solving_ leaves off by covering generics and access
types. I don't have the book in front of me right now, but I seem to
remember there also is an example that uses fixed and unbounded string
manipulation extensively.

Finally, practice using the Ada Reference Manual. It's really hard to
start your learning with it, but being able to use it is an essential
skill for Ada programmers.

HTH

Alex
From: Colin Paul Gloster on
On Sat, 17 Apr 2010, Brett sent:

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|"[..] |
| |
|I was having problems resolving the what? packages I needed to be able to process bounded strings, I'd already sucessfully written a Unbounded strings program and could not see why Bounded strings were causing me so many problems !|
|[..] |
| |
|[..] |
| |
|BTW: John Barnes Ada 2005 Book is truly excellent, [..]" |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

Why did you consider a book which makes which packages things are in
unclear by mutiliating programs by means of the USE keyword to be
excellent?
From: J-P. Rosen on
Colin Paul Gloster a �crit :

> Why did you consider a book which makes which packages things are in
> unclear by mutiliating programs by means of the USE keyword to be
> excellent?

Because it makes lisibility a lot better by drawing attention of the
reader on what actually the thing does, and getting rid of useless
information that you can find easily by clicking on the identifier and
selecting "go to declaration".

(Ok, Ok, I'm a bit provocative here, but I'm tired of seeing people
jumping on beginners and insisting on a notation that can drive them
away of the language screaming).
--
---------------------------------------------------------
J-P. Rosen (rosen(a)adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
From: Thomas Løcke "tl at on
Colin Paul Gloster wrote:
> Why did you consider a book which makes which packages things are in
> unclear by mutiliating programs by means of the USE keyword to be
> excellent?

John Barnes spends a lot of time throughout the book explaining how the
with/use clauses work, how library units work, how the
scope/visibility/accesibility systems works and how packages work. He
does not blindly "abuse" the use keyword. Quote:

"However, there is a strong school of thought that use clauses are bad
for you since they obscure the origin of entities. In order to alleviate
this dilemma there is also another form of use clause, the so-called use
type clause. This can be placed in a declarative part just a like
package clause and has similar scope. It makes just the primitive
operators of a type directly visible."

As a beginner I've had much joy out of reading the John Barnes book. It
deals with a complicated subject matter in clear and concise manner. At
least that's my experience, and I came from a more or less pure
scripting (PHP/Bash/XSLT) background, so many of the Ada concepts were
very or completely alien to me.

I think the examples in the book are very clear, if you bother to
actually READ the book, and not treat it like an Ada cookbook. So from
this beginner the book gets two thumbs up. :o)

With that said, I would personally like a book on Ada with a more
cookbook like approach, especially if it had a chapter on project files
and compiling in general.

--
Regards,
Thomas L�cke

Email: tl at ada-dk.org
Web: http:ada-dk.org
IRC nick: ThomasLocke