comp.lang.ada
 help / color / mirror / Atom feed
* Re: confusion with string initialization
  2010-04-17 13:21 confusion with string initialization brett
@ 2010-04-17 13:06 ` Georg Bauhaus
  2010-04-17 17:42 ` 
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 18+ messages in thread
From: Georg Bauhaus @ 2010-04-17 13:06 UTC (permalink / raw)


brett wrote:
> I'm trying to learn Ada 2005 with GNAT ( Linux) and are having problems with string initialization using the 
> 
> bs := 20 * " ";  
> 
> construct, which always gives an error 
> 
> "universal integer expected"

It looks like this might actually be related to
something other than your source fragment?

with Ada.Strings.Fixed;
  use Ada.Strings.Fixed;

procedure News32 is
         bs : String(1 .. 20);
begin
         bs := 20 * " ";
         bs(20) := bs(1);
end News32;

$ gnatmake -gnatwa -gnatv -gnato news32.adb
gcc-4.3 -c -gnatwa -gnatv -gnato news32.adb

GNAT 4.3.2
Copyright 1992-2007, Free Software Foundation, Inc.

Compiling: news32.adb (source file time stamp: 2010-04-17 13:02:39)
  8 lines: No errors
gnatbind -x news32.ali
gnatlink news32.ali
$



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

* confusion with string initialization
@ 2010-04-17 13:21 brett
  2010-04-17 13:06 ` Georg Bauhaus
                   ` (5 more replies)
  0 siblings, 6 replies; 18+ messages in thread
From: brett @ 2010-04-17 13:21 UTC (permalink / raw)


I'm trying to learn Ada 2005 with GNAT ( Linux) and are having problems with string initialization using the 

bs := 20 * " ";  

construct, which always gives an error 

"universal integer expected"

As my syntax is similar to that in Ada 2005 book by Barnes
(page 594 & 596) I'm a bit confused :-)
Searching the ARM was of no value either !

Thanks for any input

---
frmsrcurl: http://compgroups.net/comp.lang.ada/



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

* Re: confusion with string initialization
  2010-04-17 13:21 confusion with string initialization brett
  2010-04-17 13:06 ` Georg Bauhaus
@ 2010-04-17 17:42 ` 
  2010-04-17 19:01 ` J-P. Rosen
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 18+ messages in thread
From:  @ 2010-04-17 17:42 UTC (permalink / raw)


brett wrote:
> I'm trying to learn Ada 2005 with GNAT ( Linux) and are having problems with string initialization using the 
> 
> bs := 20 * " ";  
> 
> construct, which always gives an error 
> 
> "universal integer expected"
> 
> As my syntax is similar to that in Ada 2005 book by Barnes
> (page 594 & 596) I'm a bit confused :-)
> Searching the ARM was of no value either !
> 
> Thanks for any input

Hey Brett,

Here's how the complete example from the excellent John Barnes book 
could look:


with Ada.Strings.Bounded;           use Ada.Strings.Bounded;
with Ada.Strings.Fixed;             use Ada.Strings.Fixed;
with Ada.Strings.Unbounded;         use Ada.Strings.Unbounded;
with Ada.Text_IO;                   use Ada.Text_IO;
with Ada.Text_IO.Bounded_IO;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;

procedure String_Test is
    package Bounded_80 is new Generic_Bounded_Length (80);
    use Bounded_80;
    package Bounded_80_IO is new Bounded_IO (Bounded_80);
    use Bounded_80_IO;

    BS : Bounded_String;
    US : Unbounded_String;
    S15 : String (1 .. 15);
begin
    BS := 2 * "Bar";
    Put_Line (BS);

    US := 3 * 'A';
    Put_Line (US);

    US := 2 * US;
    Put_Line (US);

    S15 := 5 * "SOS";
    Put_Line (S15);
end String_Test;


And here's the output you should get when executing the program:

BarBar
AAA
AAAAAA
SOSSOSSOSSOSSOS

-- 
Regards,
Thomas L�cke

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



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

* Re: confusion with string initialization
  2010-04-17 13:21 confusion with string initialization brett
  2010-04-17 13:06 ` Georg Bauhaus
  2010-04-17 17:42 ` 
@ 2010-04-17 19:01 ` J-P. Rosen
  2010-04-17 21:30 ` Jeffrey R. Carter
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 18+ messages in thread
From: J-P. Rosen @ 2010-04-17 19:01 UTC (permalink / raw)


brett a �crit :
> I'm trying to learn Ada 2005 with GNAT ( Linux) and are having problems with string initialization using the 
> 
> bs := 20 * " ";  
> 
> construct, which always gives an error 
> 
> "universal integer expected"
> 

presumably, you forgot the with and/or use clauses for the
string package. Therefore the only "*" operator that's visible is the
one between universal integers (i.e. bare numbers).

Remember: you can use something in Ada only if it is made visible by the
appropriate clauses.


-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



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

* Re: confusion with string initialization
  2010-04-17 13:21 confusion with string initialization brett
                   ` (2 preceding siblings ...)
  2010-04-17 19:01 ` J-P. Rosen
@ 2010-04-17 21:30 ` Jeffrey R. Carter
  2010-04-18  2:13 ` brett
  2010-04-21  1:12 ` brett
  5 siblings, 0 replies; 18+ messages in thread
From: Jeffrey R. Carter @ 2010-04-17 21:30 UTC (permalink / raw)


On Apr 17, 6:21 am, brett <u...@compgroups.net/> wrote:
> I'm trying to learn Ada 2005 with GNAT ( Linux) and are having problems with string initialization using the
>
> bs := 20 * " ";  
>
> construct, which always gives an error
>
> "universal integer expected"

You don't really give enough information for us to give definite help.
We have no idea what the subtype of Bs is, nor what context clauses
you have.

GNAT is trying to find a function "*" that takes universal_integer (or
a type that it can be implicitly converted to) for its 1st operand,
and a string type for its right operand. Apparently no such function
is visible, and it's telling you what is needed to match a visible
function "*" that it did find. Clearly that msg isn't useful for you.

There are such functions defined in the various Ada.Strings.* pkgs.
Perhaps you have mentioned one of those in a context clause, but have
not made the function directly visible through a renaming, a use
clause, or a use type clause. You could either add such direct
visibility, or use the function's full name:

Bs := Ada.Strings.Fixed."*" (20, " ");

for example.



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

* Re: confusion with string initialization
  2010-04-17 13:21 confusion with string initialization brett
                   ` (3 preceding siblings ...)
  2010-04-17 21:30 ` Jeffrey R. Carter
@ 2010-04-18  2:13 ` brett
  2010-04-18 13:36   ` Alex Mentis
  2010-04-19 14:54   ` Colin Paul Gloster
  2010-04-21  1:12 ` brett
  5 siblings, 2 replies; 18+ messages in thread
From: brett @ 2010-04-18  2:13 UTC (permalink / raw)


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



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

* Re: confusion with string initialization
  2010-04-18  2:13 ` brett
@ 2010-04-18 13:36   ` Alex Mentis
  2010-04-19 14:54   ` Colin Paul Gloster
  1 sibling, 0 replies; 18+ messages in thread
From: Alex Mentis @ 2010-04-18 13:36 UTC (permalink / raw)


> 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



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

* Re: confusion with string initialization
  2010-04-19 14:54   ` Colin Paul Gloster
@ 2010-04-19 14:12     ` J-P. Rosen
  2010-04-19 18:20       ` John B. Matthews
  2010-04-27  9:08       ` Jacob Sparre Andersen
  2010-04-19 19:48     ` 
  1 sibling, 2 replies; 18+ messages in thread
From: J-P. Rosen @ 2010-04-19 14:12 UTC (permalink / raw)


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@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



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

* Re: confusion with string initialization
  2010-04-18  2:13 ` brett
  2010-04-18 13:36   ` Alex Mentis
@ 2010-04-19 14:54   ` Colin Paul Gloster
  2010-04-19 14:12     ` J-P. Rosen
  2010-04-19 19:48     ` 
  1 sibling, 2 replies; 18+ messages in thread
From: Colin Paul Gloster @ 2010-04-19 14:54 UTC (permalink / raw)


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?



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

* Re: confusion with string initialization
  2010-04-19 14:12     ` J-P. Rosen
@ 2010-04-19 18:20       ` John B. Matthews
  2010-04-19 23:18         ` Adam Beneschan
  2010-04-27  9:08       ` Jacob Sparre Andersen
  1 sibling, 1 reply; 18+ messages in thread
From: John B. Matthews @ 2010-04-19 18:20 UTC (permalink / raw)


In article <hqhod3$tit$1@news.eternal-september.org>,
 "J-P. Rosen" <rosen@adalog.fr> wrote:

> 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).

Preferring not to overuse "use", I recall becoming an instant fan of 
"use type" when it was introduced in Ada '95. Is there a way to make 
Ada.Strings.Fixed."*" visible without the use clause?

with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Bounded;
with Ada.Strings.Unbounded;
with Ada.Text_IO;

procedure UseType is
   package String20 is new
      Ada.Strings.Bounded.Generic_Bounded_Length(20);
   use type String20.Bounded_String;

   package StringN renames Ada.Strings.Unbounded;
   use type StringN.Unbounded_String;

   SB : constant String20.Bounded_String := 20 * '*';
   SN : constant StringN.Unbounded_String := 20 * '*';
   S1 : constant String := Ada.Strings.Fixed."*"(20, '*');
   S2 : constant String := 20 * '*';
begin
   Ada.Text_IO.Put_Line(String20.To_String(SB));
   Ada.Text_IO.Put_Line(StringN.To_String(SN));
   Ada.Text_IO.Put_Line(S1);
   Ada.Text_IO.Put_Line(S2);
end UseType;

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



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

* Re: confusion with string initialization
  2010-04-19 14:54   ` Colin Paul Gloster
  2010-04-19 14:12     ` J-P. Rosen
@ 2010-04-19 19:48     ` 
  2010-04-19 20:05       ` Warren
  2010-04-19 20:06       ` Georg Bauhaus
  1 sibling, 2 replies; 18+ messages in thread
From:  @ 2010-04-19 19:48 UTC (permalink / raw)


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



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

* Re: confusion with string initialization
  2010-04-19 19:48     ` 
@ 2010-04-19 20:05       ` Warren
  2010-04-19 20:06       ` Georg Bauhaus
  1 sibling, 0 replies; 18+ messages in thread
From: Warren @ 2010-04-19 20:05 UTC (permalink / raw)


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

Thomas L�cke expounded in news:4bccb39a$0$279$14726298@news.sunsite.dk:

> 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:
..
> 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. 

I agree. I still have and frequently review my copy of the '95
version of the book. The '05 version is still too pricey for 
my liking, even used.  I can wait for it.

Warren.



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

* Re: confusion with string initialization
  2010-04-19 19:48     ` 
  2010-04-19 20:05       ` Warren
@ 2010-04-19 20:06       ` Georg Bauhaus
  1 sibling, 0 replies; 18+ messages in thread
From: Georg Bauhaus @ 2010-04-19 20:06 UTC (permalink / raw)


Thomas L�cke schrieb:

> 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.

About the Why and How of compilation units and such:

http://archive.adaic.com/standards/83rat/html/ratl-10.html


Some of the documentation accompanying compilers is good
at explaining (and motivating) things. I found the GNAT UG
and the AppletMagic notes and articles to be valuable resources.



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

* Re: confusion with string initialization
  2010-04-19 18:20       ` John B. Matthews
@ 2010-04-19 23:18         ` Adam Beneschan
  2010-04-20  3:37           ` John B. Matthews
  0 siblings, 1 reply; 18+ messages in thread
From: Adam Beneschan @ 2010-04-19 23:18 UTC (permalink / raw)


On Apr 19, 11:20 am, "John B. Matthews" <nos...@nospam.invalid> wrote:
> In article <hqhod3$ti...@news.eternal-september.org>,
>  "J-P. Rosen" <ro...@adalog.fr> wrote:
>
> > 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).
>
> Preferring not to overuse "use", I recall becoming an instant fan of
> "use type" when it was introduced in Ada '95. Is there a way to make
> Ada.Strings.Fixed."*" visible without the use clause?

With a renaming declaration.

Before Ada 95 came out, I often included a nested package named
OPERATORS in packages that I wrote, in order to facilitate making
operators visible (often just "=").  This package would contain
renaming declarations for the operators I wanted to make visible.
Then, instead of having to USE the whole package, I could say "use
Pkg.OPERATORS" to make just the desired names visible.  That would
still work (and the package doesn't have to be nested).  You can write
your own package

with Ada.Strings.Fixed;
package Fixed_Operators is
   function "*" (Left : in Natural;
                 Right : in Character) return String
   renames Ada.Strings.Fixed."*";
   function "*" (Left : in Natural;
                 Right : in String) return String
   renames Ada.Strings.Fixed."*";
end Fixed_Operators;

and now "use Fixed_Operators;" will give you what you're looking for.
(Caveat: I have not tested the above code.)  Technically, I guess this
doesn't answer your question about how to make the operators visible
"without the use clause" [on a package], but it should be acceptable
since it only makes visible certain specific things that you *want* to
make visible, without making anything else visible that you don't want
visible.

                                      -- Adam



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

* Re: confusion with string initialization
  2010-04-19 23:18         ` Adam Beneschan
@ 2010-04-20  3:37           ` John B. Matthews
  0 siblings, 0 replies; 18+ messages in thread
From: John B. Matthews @ 2010-04-20  3:37 UTC (permalink / raw)


In article 
<30c5b01f-8620-4aa7-8bd1-8e39e0fa5296@z21g2000pre.googlegroups.com>,
 Adam Beneschan <adam@irvine.com> wrote:

> On Apr 19, 11:20 am, "John B. Matthews" <nos...@nospam.invalid> wrote:
> > In article <hqhod3$ti...@news.eternal-september.org>,
> >  "J-P. Rosen" <ro...@adalog.fr> wrote:
> >
> > > 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).
> >
> > Preferring not to overuse "use", I recall becoming an instant fan of
> > "use type" when it was introduced in Ada '95. Is there a way to make
> > Ada.Strings.Fixed."*" visible without the use clause?
> 
> With a renaming declaration.
> 
> Before Ada 95 came out, I often included a nested package named
> OPERATORS in packages that I wrote, in order to facilitate making
> operators visible (often just "=").  This package would contain
> renaming declarations for the operators I wanted to make visible.
> Then, instead of having to USE the whole package, I could say "use
> Pkg.OPERATORS" to make just the desired names visible.  That would
> still work (and the package doesn't have to be nested).  You can write
> your own package
> 
> with Ada.Strings.Fixed;
> package Fixed_Operators is
>    function "*" (Left : in Natural;
>                  Right : in Character) return String
>    renames Ada.Strings.Fixed."*";
>    function "*" (Left : in Natural;
>                  Right : in String) return String
>    renames Ada.Strings.Fixed."*";
> end Fixed_Operators;
> 
> and now "use Fixed_Operators;" will give you what you're looking for.
> (Caveat: I have not tested the above code.)  Technically, I guess this
> doesn't answer your question about how to make the operators visible
> "without the use clause" [on a package], but it should be acceptable
> since it only makes visible certain specific things that you *want* to
> make visible, without making anything else visible that you don't want
> visible.

Thanks for responding, Adam. That's exactly what I was looking for. My 
usual cohorts have sensible "use" policies, but one likes to be 
prepared. :-)

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



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

* Re: confusion with string initialization
  2010-04-17 13:21 confusion with string initialization brett
                   ` (4 preceding siblings ...)
  2010-04-18  2:13 ` brett
@ 2010-04-21  1:12 ` brett
  5 siblings, 0 replies; 18+ messages in thread
From: brett @ 2010-04-21  1:12 UTC (permalink / raw)


Alex, Thank you for your book list, your comments are much appreciated in sorting out what book to try and aquire next.

---
frmsrcurl: http://compgroups.net/comp.lang.ada/confusion-with-string-initialization



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

* Re: confusion with string initialization
  2010-04-19 14:12     ` J-P. Rosen
  2010-04-19 18:20       ` John B. Matthews
@ 2010-04-27  9:08       ` Jacob Sparre Andersen
  2010-04-28 13:26         ` BrianG
  1 sibling, 1 reply; 18+ messages in thread
From: Jacob Sparre Andersen @ 2010-04-27  9:08 UTC (permalink / raw)


J-P. Rosen wrote:
> 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).

When I taught Ada, I tried to avoid "use" (at least for newly introduced
packages) in my notes for the students.  But at the same time I
encouraged the students to use "use" in a sensible - and not quite so
limited way - in their own code.

This seemed to work reasonably well.

But simply referring the students to a "go to declaration" feature in
their editors might also be a solution, once the code is in an editor.

Greetings,

Jacob
-- 
Those who can't laugh at themselves leave the job to others.



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

* Re: confusion with string initialization
  2010-04-27  9:08       ` Jacob Sparre Andersen
@ 2010-04-28 13:26         ` BrianG
  0 siblings, 0 replies; 18+ messages in thread
From: BrianG @ 2010-04-28 13:26 UTC (permalink / raw)


Jacob Sparre Andersen wrote:
> J-P. Rosen wrote:
...
>> 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".
>>
...
> 
> But simply referring the students to a "go to declaration" feature in
> their editors might also be a solution, once the code is in an editor.
> 

And (depending on the editor) once it has been compiled, or even is able 
to be compiled.

A middle ground might be to limit yourself to a single use - then you 
know where something is from, if it's not obvious.

Personally, I prefer a renames if I want to declutter the code (once 
you've reached that, if you're teaching).

--Brian



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

end of thread, other threads:[~2010-04-28 13:26 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-17 13:21 confusion with string initialization brett
2010-04-17 13:06 ` Georg Bauhaus
2010-04-17 17:42 ` 
2010-04-17 19:01 ` J-P. Rosen
2010-04-17 21:30 ` Jeffrey R. Carter
2010-04-18  2:13 ` brett
2010-04-18 13:36   ` Alex Mentis
2010-04-19 14:54   ` Colin Paul Gloster
2010-04-19 14:12     ` J-P. Rosen
2010-04-19 18:20       ` John B. Matthews
2010-04-19 23:18         ` Adam Beneschan
2010-04-20  3:37           ` John B. Matthews
2010-04-27  9:08       ` Jacob Sparre Andersen
2010-04-28 13:26         ` BrianG
2010-04-19 19:48     ` 
2010-04-19 20:05       ` Warren
2010-04-19 20:06       ` Georg Bauhaus
2010-04-21  1:12 ` brett

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