comp.lang.ada
 help / color / mirror / Atom feed
* newbie question
@ 1999-03-18  0:00 Kenneth Lee
  1999-03-18  0:00 ` Andreas Winckler
                   ` (3 more replies)
  0 siblings, 4 replies; 62+ messages in thread
From: Kenneth Lee @ 1999-03-18  0:00 UTC (permalink / raw)


just switched to Ada a few days.
can someone show me how can i have a universal sort routine
to sort arrays of integer and float? or even strings?
i tried to implement such a generic unit, but failed coz
i'm really new to Ada :P

thx in advance.

Kenneth

PS. is there any seperate code library like those perl packages?




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

* Re: newbie question
  1999-03-18  0:00 newbie question Kenneth Lee
  1999-03-18  0:00 ` Andreas Winckler
@ 1999-03-18  0:00 ` Tom Moran
  1999-03-18  0:00   ` Kenneth Lee
  1999-03-19  0:00 ` robert_dewar
  1999-03-19  0:00 ` Michael F Brenner
  3 siblings, 1 reply; 62+ messages in thread
From: Tom Moran @ 1999-03-18  0:00 UTC (permalink / raw)


>i'm really new to Ada
What book(s) are you using?  They often have example of generic sorts.




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

* Re: newbie question
  1999-03-18  0:00 ` Tom Moran
@ 1999-03-18  0:00   ` Kenneth Lee
  1999-03-18  0:00     ` Nick Roberts
  0 siblings, 1 reply; 62+ messages in thread
From: Kenneth Lee @ 1999-03-18  0:00 UTC (permalink / raw)


Tom Moran wrote:
> 
> >i'm really new to Ada
> What book(s) are you using?  They often have example of generic sorts.

argg... don't have any book yet, i often read books at intermediate levels
maybe this time not :)
i'll find one later




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

* Re: newbie question
  1999-03-18  0:00 newbie question Kenneth Lee
@ 1999-03-18  0:00 ` Andreas Winckler
  1999-03-19  0:00   ` Kenneth Lee
  1999-03-18  0:00 ` Tom Moran
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 62+ messages in thread
From: Andreas Winckler @ 1999-03-18  0:00 UTC (permalink / raw)



Kenneth Lee schrieb:
> 
> just switched to Ada a few days.
> can someone show me how can i have a universal sort routine
> to sort arrays of integer and float? or even strings?

What compiler do you use?

GNAT comes with generic sort routines. See g-busorg.ads for bubble-sort
and g-hesorg.ads for heap-sort in your library directory.

Greetings,

AW
-- 
------------------------------------------------------------------------
Andreas Winckler                             Tel: (+49) (7541) 282 - 462
Department: MHS                              Fax: (+49) (7541) 282 - 299
FREQUENTIS Network Systems GmbH              http://www.frqnet.de
------------------------------------------------------------------------




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

* Re: newbie question
  1999-03-18  0:00   ` Kenneth Lee
@ 1999-03-18  0:00     ` Nick Roberts
  0 siblings, 0 replies; 62+ messages in thread
From: Nick Roberts @ 1999-03-18  0:00 UTC (permalink / raw)


I believe an online tutorial can be found at

http://www.adahome.com

as well as lots of other interesting stuff.

-------------------------------------
Nick Roberts
-------------------------------------








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

* Re: newbie question
  1999-03-18  0:00 ` Andreas Winckler
@ 1999-03-19  0:00   ` Kenneth Lee
  1999-03-19  0:00     ` Michael F Brenner
  0 siblings, 1 reply; 62+ messages in thread
From: Kenneth Lee @ 1999-03-19  0:00 UTC (permalink / raw)


Andreas Winckler wrote:
> 
> Kenneth Lee schrieb:
> >
> > just switched to Ada a few days.
> > can someone show me how can i have a universal sort routine
> > to sort arrays of integer and float? or even strings?
> 
> What compiler do you use?
> 
> GNAT comes with generic sort routines. See g-busorg.ads for bubble-sort
> and g-hesorg.ads for heap-sort in your library directory.
> 

thank you




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

* Re: newbie question
  1999-03-18  0:00 newbie question Kenneth Lee
  1999-03-18  0:00 ` Andreas Winckler
  1999-03-18  0:00 ` Tom Moran
@ 1999-03-19  0:00 ` robert_dewar
  1999-03-19  0:00 ` Michael F Brenner
  3 siblings, 0 replies; 62+ messages in thread
From: robert_dewar @ 1999-03-19  0:00 UTC (permalink / raw)


In article <36F039F8.275E7145@hknet.com>,
  Kenneth Lee <klch@hknet.com> wrote:
> just switched to Ada a few days.
> can someone show me how can i have a universal sort
> routine
> to sort arrays of integer and float? or even strings?
> i tried to implement such a generic unit, but failed coz
> i'm really new to Ada :P

Have a look at g-busorg.ads/b and g-busora.ads/b in the
GNAT library, to see two ways of achieving this kind of
genericity.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: newbie question
  1999-03-18  0:00 newbie question Kenneth Lee
                   ` (2 preceding siblings ...)
  1999-03-19  0:00 ` robert_dewar
@ 1999-03-19  0:00 ` Michael F Brenner
  1999-03-19  0:00   ` Nick Roberts
  3 siblings, 1 reply; 62+ messages in thread
From: Michael F Brenner @ 1999-03-19  0:00 UTC (permalink / raw)



Kenneth, if the problem is how to switch types, here is the
information. 

In Ada some things are done at compile time and some things are done
at runtime. One of the things you can do at compile time is switch
what type a package works on. For example, you can write a SORT
algorithm that works on a particular type of data called CUSTOMERS,
and it might looks like this:

      type objects is record
        -- put all the object information here
      end record;
      type indexes is range 1..243;
      type object_lists is array (indexes range <>) of objects;
      procedure sort (object_list: in out object_lists) is
      begin
        -- put your sort algorithm here
      end sort;

And you would call it like this:

      initialize (welsh_customers);
      sort (welsh_customers);

Now, to switch to use other fixed-length types such as 
any fixed length string type, any exact type such as integers,
any approximate type such as float, or any other type that
has a fixed length, you could PASS IN the types to your
sort algorithm like this:

  generic
     type indexes is range <>;
     type objects is private;
     type lists_of_objects is array (indexes range <>) of objects;
  procedure sort (list_of_objects: in out lists_of_objects); 
  begin    
    -- exactly the same sort algorithm
  end sort;

You can then instantiate this generic at compile time by passing it
the types you really want to sort, like this:

  procedure customer_sort is new sort (customer_ids, customers, call_lists);

Then you could call this instantiation at runtime as follows:

  initialize(welsh_customers);
  customer_sort (welsh_customers);

There are of course, many improvements that could be made to this
code, but this technique will generalize any simple sort algorithm
that works on fixed-length data to work on any other fixed-length
data; in order to work on variable length data, additional 
structure is needed to do the variable length, such as discriminants,
accesses, slices, dispatching, or (yuk) pointers. 



-------------------------------------------------------------------------
Kenneth said:
just switched to Ada a few days.
can someone show me how can i have a universal sort routine
to sort arrays of integer and float? or even strings?
i tried to implement such a generic unit, but failed coz
i'm really new to Ada :P

thx in advance.

Kenneth
     




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

* Re: newbie question
  1999-03-19  0:00   ` Kenneth Lee
@ 1999-03-19  0:00     ` Michael F Brenner
  1999-03-19  0:00       ` ELMO
  1999-03-21  0:00       ` Matthew Heaney
  0 siblings, 2 replies; 62+ messages in thread
From: Michael F Brenner @ 1999-03-19  0:00 UTC (permalink / raw)


>> GNAT comes with generic sort routines. See g-busorg.ads for bubble-sort
>> and g-hesorg.ads for heap-sort in your library directory.
> thank you          

Yes, thank you. I did not know this. I guess I have to start
looking at all the g- routines in Lib to see what is there.
Already existing code can be a valuable addition to a compiler.





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

* Re: newbie question
  1999-03-19  0:00     ` Michael F Brenner
@ 1999-03-19  0:00       ` ELMO
  1999-03-21  0:00       ` Matthew Heaney
  1 sibling, 0 replies; 62+ messages in thread
From: ELMO @ 1999-03-19  0:00 UTC (permalink / raw)


Dr. Beidler has an on-line hypercode version of many of the gnat specs
at:

http://www.cs.uofs.edu/~beidler/Ada/adlibr.html

David Botton


Michael F Brenner wrote:
> 
> >> GNAT comes with generic sort routines. See g-busorg.ads for bubble-sort
> >> and g-hesorg.ads for heap-sort in your library directory.
> > thank you
> 
> Yes, thank you. I did not know this. I guess I have to start
> looking at all the g- routines in Lib to see what is there.
> Already existing code can be a valuable addition to a compiler.




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

* Re: newbie question
  1999-03-19  0:00 ` Michael F Brenner
@ 1999-03-19  0:00   ` Nick Roberts
  1999-03-20  0:00     ` Nick Roberts
  0 siblings, 1 reply; 62+ messages in thread
From: Nick Roberts @ 1999-03-19  0:00 UTC (permalink / raw)


Crucially, one of the things you can pass as a generic parameter into a
generic unit is a procedure or function.  Furthermore, the parameter types
of the parameters (and return types) of these can be other generic
parameters (which must appear beforehand).

Thus one might declare:

   generic
      type Element_Type is private;
      type Index_Type is (<>);
      type Array_Type is array (Index_Type) of Element_Type;
      with procedure Swap (Item1, Item_2: in out Element_Type) is <>;
      with function "<=" (Left, Right: in Element_Type) return Boolean is
<>;

   procedure My_Sort (Object: in out Array_Type; From, To: Index_Type);

and complete this declaration with a body:

   procedure My_Sort (Object: in out Array_Type; From, To: Index_Type) is
      ...
   end My_Sort;

within which you can refer to the generic parameters (almost) as if they
were ordinary examples of the corresponding kinds of entity.

The 'is <>' at the end of the procedure and function generic parameters
allow an instantiation of the generic procedure (My_Sort) to be omitted, if
there is a suitable procedure or function already in existence which has the
same name ('Swap' or the operator "<=").  A lot of types already have "<="
defined for them (the predefined types Integer, Float, and String, for
example).

The generic procedure can then be 'instantiated' to create a specific
procedure which can actually be called.  For example, supposing we had:

   type Day is (Monday, ..., Sunday);

   type Earnings is array (Day) of Float;

   procedure Swap (F1, F2: in out Float) is
      F3: constant Float := F1;
   begin
      F1 := F2;
      F2 := F3;
   end Swap;

we could then declare the following instantiation:

   procedure Sort_Earnings is new My_Sort(Float,Day,Earnings);

The procedure Sort_Earnings will sort an array of the type Earnings.  The
generic parameters 'Swap' and "<=" did not have to explicitly passed in the
instantiation, because they already existed, and could be 'assumed'.

I hope this is not too complicated to take in in one gulp!  A good textbook,
tutor, friendly local expert, or online tutorial will repay your study.
Best of luck.

-------------------------------------
Nick Roberts
-------------------------------------








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

* Re: newbie question
  1999-03-19  0:00   ` Nick Roberts
@ 1999-03-20  0:00     ` Nick Roberts
  0 siblings, 0 replies; 62+ messages in thread
From: Nick Roberts @ 1999-03-20  0:00 UTC (permalink / raw)


I got my tongue in a twist when I said

|The 'is <>' at the end of the procedure and function generic parameters
|allow an instantiation of the generic procedure (My_Sort) to be omitted, if
|there is a suitable procedure or function already in existence which has
the
|same name ('Swap' or the operator "<=").  A lot of types already have "<="
|defined for them (the predefined types Integer, Float, and String, for
|example).


The correct version would be:

>>> The 'is <>' at the end of the procedure and function generic parameters
allow an actual function or procedure to be omitted from an instantiation of
the generic procedure (My_Sort) , if there is a suitable procedure or
function already in existence which has the same name ('Swap' or the
operator "<=").  A lot of types already have "<=" defined for them (the
predefined types Integer, Float, and String, for example). <<<

If you listen very closely, you can actually hear the synapses in my brain
clicking.

(Occasionally :-)

-------------------------------------
Nick Roberts
-------------------------------------








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

* Re: newbie question
  1999-03-19  0:00     ` Michael F Brenner
  1999-03-19  0:00       ` ELMO
@ 1999-03-21  0:00       ` Matthew Heaney
  1 sibling, 0 replies; 62+ messages in thread
From: Matthew Heaney @ 1999-03-21  0:00 UTC (permalink / raw)


mfb@mbunix.mitre.org (Michael F Brenner) writes:

> >> GNAT comes with generic sort routines. See g-busorg.ads for bubble-sort
> >> and g-hesorg.ads for heap-sort in your library directory.
> > thank you          
> 
> Yes, thank you. I did not know this. I guess I have to start
> looking at all the g- routines in Lib to see what is there.
> Already existing code can be a valuable addition to a compiler.


Here's a portion of the gnat package tree:

Ada package hierarchy tree (based on GNAT 3.11p ACT distribution
sources) date 3/2/99. by Nasser Abbasi <mailto:nabbasi@pacbell.net>.
Free to copy, distribute in any way. Not responsible for errors.
Updated copies can be found at <http://home.pacbell.net/nma123>.
===============================================================

                    G N A T  package
          -----------------------------------

                +- Bubble_Sort_A
                |
                +- Bubble_Sort_G
                |
                +- Case_Util
                |
                +- Command_Line
                |
                +- Debug_Utilities
                |
                +- Directory_Operations
                |
                +- Heap_Sort_A
                |
          GNAT -+- Heap_Sort_G
                |
                +- HTable 
                |
                +- IO -+- IO_Aux
                |
                +- OS_Lib
                |
                +- Regexp
                |
                |           +- Patterns
                |           |
                |           +- Table_Boolean 
                |           |
                +- Spitbol -+- Table_Integer
                |           |
                |           +- Table_VString
                |   
                +- Table
                |
                +- Task_Lock
     





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

* Newbie question
@ 2000-05-25  0:00 olsonm76
  2000-05-26  0:00 ` Robert Dewar
  0 siblings, 1 reply; 62+ messages in thread
From: olsonm76 @ 2000-05-25  0:00 UTC (permalink / raw)


I have been working with a program written in ADA for the last year and
a half, on a SCO Unix OS.  Well I need to make some changes to the
program and have no idea where to find the compiler so I can start
reading the code. HELP please.


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Newbie question
  2000-05-25  0:00 olsonm76
@ 2000-05-26  0:00 ` Robert Dewar
  0 siblings, 0 replies; 62+ messages in thread
From: Robert Dewar @ 2000-05-26  0:00 UTC (permalink / raw)


In article <8gk046$osq$1@nnrp1.deja.com>,
  olsonm76@my-deja.com wrote:
> I have been working with a program written in ADA for the last
year and
> a half, on a SCO Unix OS.  Well I need to make some changes to
the
> program and have no idea where to find the compiler so I can
start
> reading the code. HELP please.


Ada Core Technologies provides a version of GNAT Professional
for SCO Unix. Contact sales@gnat.com for further details.

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Newbie question
@ 2001-12-24 13:52 Jasbinder S  Uppal
  2001-12-24 20:06 ` Michal Nowak
  0 siblings, 1 reply; 62+ messages in thread
From: Jasbinder S  Uppal @ 2001-12-24 13:52 UTC (permalink / raw)


Hi, I've been subscribed to this news group for a long time (ok, when I
first started using Ada, about 2 months ago!), but this is the first time
I've actually had problems with the language and well, I was wondering if
you guys can help me.

I've got this assignment for university that I have to do, and I am having
problems with the first bit (Not a good sign, is it....).
I've got a data file, which contains a line of data for a vehicle, and on
the line, it gives a place name, a registration number, and the time that
the car goes onto a motorway. A typical line is as follows....

Barnsley    A123       22    15    40
....
....
Where Barnsley is the place, A123 is the Registration number, and 22  15
40 is the time (22:15:40). I've managed to get the Place name (using
characters) and the registration number (using Strings), and putting it into
a record, but I am unsure as to what to use for the time. I could (I think)
use characters, but I need to manipulate the times later on in the program
(which could be done by having the time as an integer), but because there
are blanks in between the numbers, I am unsure as to how I can do this. Help
me please....

I appreciate any help given.

Thanks.

J





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

* Re: Newbie question
  2001-12-24 13:52 Newbie question Jasbinder S  Uppal
@ 2001-12-24 20:06 ` Michal Nowak
  2001-12-24 21:13   ` martin.m.dowie
  0 siblings, 1 reply; 62+ messages in thread
From: Michal Nowak @ 2001-12-24 20:06 UTC (permalink / raw)
  To: comp.lang.ada usegroup->mailing list gateway

On 01-12-24 at 13:52 Jasbinder S Uppal wrote:

>Hi, I've been subscribed to this news group for a long time (ok, when I
>first started using Ada, about 2 months ago!), but this is the first time
>I've actually had problems with the language and well, I was wondering if
>you guys can help me.

Welcome newbie, from another newbie :-))

>I've got this assignment for university that I have to do, and I am having
>problems with the first bit (Not a good sign, is it....).
>I've got a data file, which contains a line of data for a vehicle, and on
>the line, it gives a place name, a registration number, and the time that
>the car goes onto a motorway. A typical line is as follows....
>
>Barnsley    A123       22    15    40
>....
>....
>Where Barnsley is the place, A123 is the Registration number, and 22  15
>40 is the time (22:15:40). I've managed to get the Place name (using
>characters) and the registration number (using Strings), and putting it
>into
>a record, but I am unsure as to what to use for the time. I could (I think)
>use characters, but I need to manipulate the times later on in the program
>(which could be done by having the time as an integer), but because there
>are blanks in between the numbers, I am unsure as to how I can do this.
>Help
>me please....
>
>I appreciate any help given.
>
>Thanks.

As I said, I'm newbie also, but maybe this will be helpful.

Generally speaking, you may do like this:

...
Read place name,
Read registration number,
skip spaces,
read hour,
skip spaces,
read minute,
skip spces,
read second.
...

However, reading character after character from disc file is
inefficient way. My proposal is to read whole line into a string.
I assume, that hours, minutes and seconds are two digits
numbers (so the hour 7AM is presented as 07).
If no, you will have a bit more work.

Extract place name from string
Extract registration number
Skip Spaces
   You should know on which position in the string you are
   after skipping spaces. Let's call it Current_Position and
   let Whole_Line be of type String and consist line from
   input file.
   Hour := Integer'Value (Whole_Line(Current_Position .. Current'Position + 2) );

   Hour is of type Integer. It does not has to be predefined
   Integer. You may do something like this:
   type Hour_Type is range 0 .. 23; --this is declaration of
                                    --integer type
   Hour : Hour_Type;
   However, if you declare Hour_Type as a distinct type, you will
   have to cast result of Integer'Value to Hour_Type before assigning
   it to Hour:

   Hour := Hour_Type (Integer'Value (
                        Whole_Line(Current_Position .. Current'Position + 2) )
                     );

Do the same for minutes and seconds.
Exception handling is your task to do.

I'm not sure if this is very elegant way of doing it, but as
I said, I'm still a newbie.

I hope this will help you in some way.
Happy Ada programming,
-Mike
-----------------------------------------
                             ____|
                             \%/ |~~\
  O                                  |
 o>>        Mike Nowak               |
 T                                   |
/ >       vinnie@inetia.pl           |
http://www.geocities.com/vinnie14pl _|__




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

* Re: Newbie question
  2001-12-24 20:06 ` Michal Nowak
@ 2001-12-24 21:13   ` martin.m.dowie
  2001-12-25 12:36     ` Michal Nowak
  0 siblings, 1 reply; 62+ messages in thread
From: martin.m.dowie @ 2001-12-24 21:13 UTC (permalink / raw)


"Michal Nowak" <vinnie@inetia.pl> wrote in message
news:mailman.1009224122.1572.comp.lang.ada@ada.eu.org...
> On 01-12-24 at 13:52 Jasbinder S Uppal wrote:
>
> Welcome newbie, from another newbie :-))

Ditto!


[snipped problem]
>    Hour is of type Integer. It does not has to be predefined
>    Integer. You may do something like this:
>    type Hour_Type is range 0 .. 23; --this is declaration of
>                                     --integer type
>    Hour : Hour_Type;
>    However, if you declare Hour_Type as a distinct type, you will
>    have to cast result of Integer'Value to Hour_Type before assigning
>    it to Hour:
>
>    Hour := Hour_Type (Integer'Value (
>                         Whole_Line(Current_Position .. Current'Position +
2) )
>                      );
>

The bit about casting (in Ada usually called 'type converting') is a little
over the top as Hour_Type has access to the attribute 'Value too. So it
is a little simpler:

Hour :=
   Hour_Type'Value (Whole_Line (Current_Position .. Current_Position + 2));






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

* Re: Newbie question
  2001-12-24 21:13   ` martin.m.dowie
@ 2001-12-25 12:36     ` Michal Nowak
  2001-12-27 14:25       ` Alfred Hilscher
  0 siblings, 1 reply; 62+ messages in thread
From: Michal Nowak @ 2001-12-25 12:36 UTC (permalink / raw)
  To: comp.lang.ada usegroup->mailing list gateway

On 01-12-24 at 21:13 martin.m.dowie wrote:

>"Michal Nowak" <vinnie@inetia.pl> wrote in message

>>    Hour is of type Integer. It does not has to be predefined
>>    Integer. You may do something like this:
>>    type Hour_Type is range 0 .. 23; --this is declaration of
>>                                     --integer type
>>    Hour : Hour_Type;
>>    However, if you declare Hour_Type as a distinct type, you will
>>    have to cast result of Integer'Value to Hour_Type before assigning
>>    it to Hour:
>>
>>    Hour := Hour_Type (Integer'Value (
>>                         Whole_Line(Current_Position .. Current'Position +
>2) )
>>                      );
>>
>
>The bit about casting (in Ada usually called 'type converting') is a little
>over the top as Hour_Type has access to the attribute 'Value too.

Oh, in fact. My fault, my apologizes.

So it
>is a little simpler:
>
>Hour :=
>   Hour_Type'Value (Whole_Line (Current_Position .. Current_Position + 2));
                                                                       ^^^^
There was another little one. It should be Current_Position + 1 (assuming,
that hour is two digit, and Current_Position is position of first digit).

It looks that working with high temperature does not has good results.
Getting back to bed now.
Bye!

Mike
-----------------------------------------
                             ____|
                             \%/ |~~\
  O                                  |
 o>>        Mike Nowak               |
 T                                   |
/ >       vinnie@inetia.pl           |
http://www.geocities.com/vinnie14pl _|__




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

* Re: Newbie question
  2001-12-25 12:36     ` Michal Nowak
@ 2001-12-27 14:25       ` Alfred Hilscher
  2001-12-29 21:54         ` Michal Nowak
  0 siblings, 1 reply; 62+ messages in thread
From: Alfred Hilscher @ 2001-12-27 14:25 UTC (permalink / raw)




Michal Nowak wrote:
> >Hour :=
> >   Hour_Type'Value (Whole_Line (Current_Position .. Current_Position + 2));
>                                                                        ^^^^
> There was another little one. It should be Current_Position + 1 (assuming,
> that hour is two digit, and Current_Position is position of first digit).

Another way would be to search for the first digit and then search from
there to the first non digit, so you can handle both, one-digit hours
and two-digit hours:

Hour :=  Hour_Type'Value (Whole_Line (First_Digit .. First_Non_Digit -
1));



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

* Re: Newbie question
  2001-12-27 14:25       ` Alfred Hilscher
@ 2001-12-29 21:54         ` Michal Nowak
  2001-12-31 17:51           ` Jasbinder S Uppal
  0 siblings, 1 reply; 62+ messages in thread
From: Michal Nowak @ 2001-12-29 21:54 UTC (permalink / raw)
  To: comp.lang.ada usegroup->mailing list gateway

On 01-12-27 at 15:25 Alfred Hilscher wrote:

>Michal Nowak wrote:
>> >Hour :=
>> >   Hour_Type'Value (Whole_Line (Current_Position .. Current_Position +
>2));
>>
>^^^^
>> There was another little one. It should be Current_Position + 1
>(assuming,
>> that hour is two digit, and Current_Position is position of first digit).
>
>Another way would be to search for the first digit and then search from
>there to the first non digit, so you can handle both, one-digit hours
>and two-digit hours:
>
>Hour :=  Hour_Type'Value (Whole_Line (First_Digit .. First_Non_Digit -
>1));

I just wanted the simplest way and was still thinking in terms of C-style
strings (if they exist). Today's morning in the bed I passed chapter 5
of Cohen's book (String handling). Yea, Find_Token should do the trick.

Mike




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

* Re: Newbie question
  2001-12-29 21:54         ` Michal Nowak
@ 2001-12-31 17:51           ` Jasbinder S Uppal
  2002-01-01 21:26             ` Michal Nowak
  0 siblings, 1 reply; 62+ messages in thread
From: Jasbinder S Uppal @ 2001-12-31 17:51 UTC (permalink / raw)


Just wanted 2 say thanks for all the advice I've been given, it much
appreciated.

I have to say that in some places, the description of the suggestion went
RIGHT over my head, but it did give me an idea of how to do the problem.

I started from the start of the line, and looped till a blank (' ') was
found, (thus giving me the location) and then loop until a character is
found, then again loop until a blank is found (thus giving me the
registration number) and then AGAIN loop until the blanks finish, then get
the hours (which I assigned to integers). Because there was a constant 3
spaces between the hours, minutes and seconds, I continued this process till
I got the whole line. I know this might not seem like the most efficient
option, but I am not really that good at Ada, and so this is the only option
I could understand.

Now I am going onto the next bit which is even more difficult, and I havent
got a hope of doing it (I'm not a fan of arrays :S).Oh well, theres a
struggle ahead :)

Thanks again

J

PS Michal hope ur feeling better, if not, a dose of Ada will certainly fix
any ailments u have.....





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

* Re: Newbie question
  2001-12-31 17:51           ` Jasbinder S Uppal
@ 2002-01-01 21:26             ` Michal Nowak
  0 siblings, 0 replies; 62+ messages in thread
From: Michal Nowak @ 2002-01-01 21:26 UTC (permalink / raw)
  To: comp.lang.ada usegroup->mailing list gateway

On 01-12-31 at 17:51 Jasbinder S Uppal wrote:

[snip]

>PS Michal hope ur feeling better, if not, a dose of Ada will certainly fix
>any ailments u have.....

Thank you sincerely, I'm OK now. I'm glad I've been a bit helpful. I hope
that the errors I made did not confused you. I'm newbie also...My advices
were a bit in C-tone, I wasn't well aware of Ada strings. I learned a bit
more when I was lying in bed and reading Cohen's book. Maybe this will be
more helpful than my last "advices".
If you have access to Reference Manual (HTML files are installed with GNAT,
so you should), look at Annex A, section 4 (particularly 4.2).
There is useful package Ada.Strings.Maps and Ada.Strings.Fixed (the latter
in case if you use fixed length Strings). It will be much easir to parse
the input line using functions and procedures from these packages. I think
that procedure Find_Token will be helpful. A token can be a sequence of
characters belonging to some set. The second parameter of Find_Token is of
type Character_Set. As I remember, the first word was the name of place
(so it consists of upper and lowercase letters) and the second was road
number (consisting of letters and numbers) and the rest was hour (only
numbers). In Ada.Strings.Maps.Constants there are predefined sets of
chracters:
Alphanumeric_Set : ISO-8859-1 letters and numbers,
Letter_Set : ISO-8859-1 letters,
Decimal_Digit_Set : Decimal numbers.

Alphanumeric_Set consists not only Enlish letters, but also letters with
diacritical marks. This piece of code shows chracters from this set:

with Ada.Strings.Maps.Constants;
    use Ada.Strings.Maps;  --for procedures
    use Ada.Strings.Maps.Constants; --for constant sets
with Ada.Text_IO;
    use Ada.Text_IO;

procedure Show_Set is
begin
    Put (To_Sequence(Alphanumeric_Set) );
end Show_Set;

If you apply Find_Token to extracting values, all can be written
like this:
Find_Token (Input_Line, Letter_Set, Inside, From, To);

In From and To variables you will get beginning and end of first
word. You may than use slice operation to get the first word into
string:
Place := To_Unbounded_String (Input_Line (From .. To) );
(I assume here, that place is of type Unbounded_String, declared in
Ada.Strings.Unbounded, you may need to "with" this package);

Than you may repeat the search for the second word:
Find_Token (Input_Line (To + 1 .. Input_Line'Last), Letter_Set, Inside, From, To);
                        ^^
     This To was obtained in first call to Find_Token.

And then extract the second word and do the same for numbers.

I hope I was more helpful now and that I was not to late.
Enjoy,
Mike(
-----------------------------------------
                             ____|
                             \%/ |~~\
  O                                  |
 o>>        Mike Nowak               |
 T                                   |
/ >       vinnie@inetia.pl           |
http://www.geocities.com/vinnie14pl _|__




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

* Newbie Question.
@ 2004-08-04  6:42 leke
  2004-08-04  8:55 ` Frank
  2004-08-04  9:51 ` Martin Dowie
  0 siblings, 2 replies; 62+ messages in thread
From: leke @ 2004-08-04  6:42 UTC (permalink / raw)


1) What is the best bit of on-line reading a newbie to programming can
get for learning ADA?

2) Do the government still use ADA for what it was designed for?



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

* Re: Newbie Question.
  2004-08-04  6:42 Newbie Question leke
@ 2004-08-04  8:55 ` Frank
  2004-08-04  9:51 ` Martin Dowie
  1 sibling, 0 replies; 62+ messages in thread
From: Frank @ 2004-08-04  8:55 UTC (permalink / raw)


Hi!

Try "Learning Center" on http://www.adaworld.com

Frank





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

* Re: Newbie Question.
  2004-08-04  6:42 Newbie Question leke
  2004-08-04  8:55 ` Frank
@ 2004-08-04  9:51 ` Martin Dowie
  1 sibling, 0 replies; 62+ messages in thread
From: Martin Dowie @ 2004-08-04  9:51 UTC (permalink / raw)


leke wrote:
> 1) What is the best bit of on-line reading a newbie to programming can
> get for learning ADA?

To learn "Ada" (not ADA) try the following on-line books:

http://www.adapower.com/learn/adadistilled.html
http://www.it.bton.ac.uk/staff/je/adacraft/
http://burks.bton.ac.uk/burks/language/ada/ada95.pdf

> 2) Do the government still use ADA for what it was designed for?

It's not just the US govenment (by that I take it you mean military) that
uses Ada. Here's a page dedicated to logging Ada using
companies/organisations

http://www.seas.gwu.edu/~mfeldman/ada-project-summary.html

Have fun! :-)

Cheers

-- Martin





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

* newbie question...
@ 2005-07-03 17:58 e.coli
  2005-07-03 18:32 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 62+ messages in thread
From: e.coli @ 2005-07-03 17:58 UTC (permalink / raw)


what is the difference?:

accept foo;
...
code


accept foo do
...
same code above
...
end foo;


thaks




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

* Re: newbie question...
  2005-07-03 17:58 newbie question e.coli
@ 2005-07-03 18:32 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 62+ messages in thread
From: Dmitry A. Kazakov @ 2005-07-03 18:32 UTC (permalink / raw)


On 3 Jul 2005 10:58:49 -0700, e.coli wrote:

> what is the difference?:
> 
> accept foo;
> ...
> code

The code is executed after the rendezvous with the task that has called
foo, i.e. asynchronously to that task.

> accept foo do
> ...
> same code above
> ...
> end foo;

The code will be executed during the rendezvous, synchronously to the task
that calls foo. The caller's task is blocked between its call to foo and
"end foo;". After "end foo;" both tasks continue their work independently
on each other.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Newbie question
@ 2005-07-18 11:26 Francisco J. Montoya
  2005-07-18 13:14 ` Martin Dowie
                   ` (2 more replies)
  0 siblings, 3 replies; 62+ messages in thread
From: Francisco J. Montoya @ 2005-07-18 11:26 UTC (permalink / raw)


Platform: WinXP SP2
Compiler: GNAT Public Ada 95 Environment 3.15p
(also using: AdaGide 7.30)

[apologies if this is a recurrente topic. I found nothing in the FAQ 
group list http://www.adahome.com/FAQ/comp-lang-ada.html]

------------------------------

Hello all.

Just a brief and (hopefully) easy question from a clumsy Ada newbie like me:

Is there any way to keep packages (writen by me, I mean) into a separate 
directory diffetent from the one where the program(s) that make use of 
them is(are)?

I figure out this could be done by setting right options in the dialog 
"Project settings", and "Debug/Release settings" -> "Compiler Options" 
and "Gnatmake" therein, but I haven't succeeded in finding them in the 
compiler documentation.

Thank you very much in advance, and accept my apologies for stealing 
your worthy time.

Regards,


P.S.: I'll be out from my office for August, so I would appreciate it if 
you were so nice to send me your answer (if any) to my personal account 
e-mail address instead of (or besides) replying to the group, if you do 
so in August or near. Thank you again.


-- 
Francisco J. Montoya
Depto. Informatica y Sistemas, Facultad de Informatica
(E-30071 Campus de Espinardo) Universidad de Murcia (Spain)
Voice: +34 968 364620, Fax: +34 968 364151, e-mail: fmontoya-AT-dif.um.es




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

* Re: Newbie question
  2005-07-18 11:26 Newbie question Francisco J. Montoya
@ 2005-07-18 13:14 ` Martin Dowie
  2005-07-18 13:51   ` Alex R. Mosteo
  2005-07-18 15:28 ` Jeffrey Carter
  2005-07-18 17:40 ` Martin Krischik
  2 siblings, 1 reply; 62+ messages in thread
From: Martin Dowie @ 2005-07-18 13:14 UTC (permalink / raw)


Francisco J. Montoya wrote:
> I figure out this could be done by setting right options in the dialog
> "Project settings", and "Debug/Release settings" -> "Compiler Options"
> and "Gnatmake" therein, but I haven't succeeded in finding them in the
> compiler documentation.

-D <dir>

Cheers

-- Martin





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

* Re: Newbie question
  2005-07-18 13:14 ` Martin Dowie
@ 2005-07-18 13:51   ` Alex R. Mosteo
  2005-07-18 20:27     ` Martin Dowie
  0 siblings, 1 reply; 62+ messages in thread
From: Alex R. Mosteo @ 2005-07-18 13:51 UTC (permalink / raw)


Martin Dowie wrote:
> Francisco J. Montoya wrote:
> 
>>I figure out this could be done by setting right options in the dialog
>>"Project settings", and "Debug/Release settings" -> "Compiler Options"
>>and "Gnatmake" therein, but I haven't succeeded in finding them in the
>>compiler documentation.
> 
> 
> -D <dir>

Wouldn't this be -I
?



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

* Re: Newbie question
  2005-07-18 11:26 Newbie question Francisco J. Montoya
  2005-07-18 13:14 ` Martin Dowie
@ 2005-07-18 15:28 ` Jeffrey Carter
  2005-07-18 17:40 ` Martin Krischik
  2 siblings, 0 replies; 62+ messages in thread
From: Jeffrey Carter @ 2005-07-18 15:28 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

Francisco J. Montoya wrote:
> 
> Is there any way to keep packages (writen by me, I mean) into a separate 
> directory diffetent from the one where the program(s) that make use of 
> them is(are)?

This is compiler dependent. With GNAT, you have 2 options:

1. The -I switch.

2. The ADA_INCLUDE_PATH & ADA_OBJECTS_PATH environment variables.

Both are described in the compiler documentation.

For AdaGIDE, option 2. requires no additional effort. Option 1. requires 
that you specify the switch in the "Project settings in current 
directory" dialog for every directory in which you use them.

[-- Attachment #2: spam.vcf --]
[-- Type: text/x-vcard, Size: 177 bytes --]

begin:vcard
fn:Jeffrey Carter
n:;Jeffrey Carter
email;internet:jeffrey_r_carter-nr [commercial-at] raytheon [period | full stop] com
x-mozilla-html:FALSE
version:2.1
end:vcard


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

* Re: Newbie question
  2005-07-18 11:26 Newbie question Francisco J. Montoya
  2005-07-18 13:14 ` Martin Dowie
  2005-07-18 15:28 ` Jeffrey Carter
@ 2005-07-18 17:40 ` Martin Krischik
  2 siblings, 0 replies; 62+ messages in thread
From: Martin Krischik @ 2005-07-18 17:40 UTC (permalink / raw)


Francisco J. Montoya wrote:

> I figure out this could be done by setting right options in the dialog
> "Project settings", and "Debug/Release settings" -> "Compiler Options"
> and "Gnatmake" therein, but I haven't succeeded in finding them in the
> compiler documentation.

just type gnat compile into your favourite commandline and you get (among a
hundred more lines):

Source and Library search path switches:
  -aLdir    Skip missing library sources if ali in dir
  -Adir     like -aLdir -aIdir
  -aOdir    Specify library/object files search path
  -aIdir    Specify source files search path
  -Idir     Like -aIdir -aOdir
  -I-       Don't look for sources & library files in the default directory
  -Ldir     Look for program libraries also in dir
  -nostdinc Don't look for sources in the system default directory
  -nostdlib Don't look for library files in the system default directory
  --RTS=dir specify the default source and object search path

> Thank you very much in advance, and accept my apologies for stealing
> your worthy time.

You are welcome

Martin

-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com




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

* Re: Newbie question
  2005-07-18 13:51   ` Alex R. Mosteo
@ 2005-07-18 20:27     ` Martin Dowie
  0 siblings, 0 replies; 62+ messages in thread
From: Martin Dowie @ 2005-07-18 20:27 UTC (permalink / raw)


Alex R. Mosteo wrote:
> Martin Dowie wrote:
> 
>> Francisco J. Montoya wrote:
>>
>>> I figure out this could be done by setting right options in the dialog
>>> "Project settings", and "Debug/Release settings" -> "Compiler Options"
>>> and "Gnatmake" therein, but I haven't succeeded in finding them in the
>>> compiler documentation.
>>
>>
>>
>> -D <dir>
> 
> 
> Wouldn't this be -I
> ?

Oops sorry, yes. I misread it and thought the question was about keeping 
the resulting library files in a different location.

-- Martin



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

* Newbie question
@ 2007-11-23 13:22 Sir Chewbury Gubbins
  2007-11-23 14:01 ` Sir Chewbury Gubbins
  2007-11-24 16:49 ` Stephen Leake
  0 siblings, 2 replies; 62+ messages in thread
From: Sir Chewbury Gubbins @ 2007-11-23 13:22 UTC (permalink / raw)



Good afternoon! I apologise if this is an eye-rolly question, but
I'm having a bit of an issue using Gnat with the Lovelace tutorial.

A trivial example - the "Compute" procedure on:

http://www.adahome.com/Tutorials/Lovelace/s1sf.htm

contains a sub procedure which does:

	loop
		Put(X);
		New_Line(X);
		Double(X);
	end loop;

All fine - X is defined as an integer and initialised to 1. Now, if I
comment out the loop and end loop, the program outputs one as expected. 
If I duplicate the three lines and run it again, I get a 1 and a 2 as
expected. If I stick the infinite loop back in, I don't get the expected
series of doublings, but just an infinite number of zeros.

It *looks* as though X magically becomes out of scope within the loop, but
I can't see why that would be the case. 

Anyone shed any light on this?

Regards

Choobs

-- 
     Sir Chewbury Gubbins <choobs@chewbury.net.invalid>
 ...   Blog : http://www.nelefa.org
 /|\ 	 Game Diary : http://www.chewbury.net
/ | \      Abu the Monkey was never naughty.



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

* Re: Newbie question
  2007-11-23 13:22 Sir Chewbury Gubbins
@ 2007-11-23 14:01 ` Sir Chewbury Gubbins
  2007-11-24 16:49 ` Stephen Leake
  1 sibling, 0 replies; 62+ messages in thread
From: Sir Chewbury Gubbins @ 2007-11-23 14:01 UTC (permalink / raw)


Sir Chewbury Gubbins the Monkey was never naughty:
>
> Good afternoon! I apologise if this is an eye-rolly question, but
> I'm having a bit of an issue using Gnat with the Lovelace tutorial.

Sorry - was a bit brain dead. I've worked out what was happening - 
with no exception checking in place, the code was quickly overflowing
and printing zeroes after just a few iterations, then scrolling 
the numbers past the top of the terminal :)

I'll get my coat.

Choobs

-- 
     Sir Chewbury Gubbins <choobs@chewbury.net.invalid>
 ...   Blog : http://www.nelefa.org
 /|\ 	 Game Diary : http://www.chewbury.net
/ | \      Abu the Monkey was never naughty.



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

* Re: Newbie question
  2007-11-23 13:22 Sir Chewbury Gubbins
  2007-11-23 14:01 ` Sir Chewbury Gubbins
@ 2007-11-24 16:49 ` Stephen Leake
  2007-11-24 17:08   ` Peter C. Chapin
  2007-11-29  0:46   ` Robert A Duff
  1 sibling, 2 replies; 62+ messages in thread
From: Stephen Leake @ 2007-11-24 16:49 UTC (permalink / raw)


Sir Chewbury Gubbins <chewbury.gubbins@nelefa.org.invalid> writes:

> Good afternoon! I apologise if this is an eye-rolly question, but
> I'm having a bit of an issue using Gnat with the Lovelace tutorial.
>
> A trivial example - the "Compute" procedure on:
>
> http://www.adahome.com/Tutorials/Lovelace/s1sf.htm

Here's a modified version, that always exits the loop:

with Ada.Text_IO;         use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Compute is

   procedure Double (Item : in out Integer) is
   begin -- procedure Double.
      Item := Item * 2;
   end Double;

   X : Integer := 1;   -- Local variable X of type Integer.

   I : Integer := 1; -- loop counter
begin -- procedure Compute
   loop
      I := I + 1;
      exit when I > 50;
      Put (X);
      New_Line;
      Double (X);
   end loop;
end Compute;

If you compile this with the default GNAT options, you get:

bash-3.2$ stephe@LM000850872$ gnatmake compute
gcc -c compute.adb
gnatbind -x compute.ali
gnatlink compute.ali
stephe@LM000850872$ ./compute
          1
          2
          4
          8
         16
         32
         64
        128
        256
        512
       1024
       2048
       4096
       8192
      16384
      32768
      65536
     131072
     262144
     524288
    1048576
    2097152
    4194304
    8388608
   16777216
   33554432
   67108864
  134217728
  268435456
  536870912
 1073741824
-2147483648
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
stephe@LM000850872$ 

If you compile with -gnato, you get:

stephe@LM000850872$ rm *.o
stephe@LM000850872$ gnatmake compute -gnato
gcc -c -gnato compute.adb
gnatbind -x compute.ali
gnatlink compute.ali
stephe@LM000850872$ ./compute
          1
          2
          4
          8
         16
         32
         64
        128
        256
        512
       1024
       2048
       4096
       8192
      16384
      32768
      65536
     131072
     262144
     524288
    1048576
    2097152
    4194304
    8388608
   16777216
   33554432
   67108864
  134217728
  268435456
  536870912
 1073741824

raised CONSTRAINT_ERROR : compute.adb:7 overflow check failed
stephe@LM000850872$ 

> If I stick the infinite loop back in, I don't get the expected
> series of doublings, but just an infinite number of zeros.

I suspect you missed the initial counting, because it scrolls off the
screen so quickly. Another option is to add a "delay 1.0;" to the
loop, so you can see it count.

One point of this excercise, as the questions following it show, is to
demonstrate that Ada raises exceptions when things go wrong, instead
of silently doing the wrong thing.

However, as has been pointed out many times here, GNAT with the
default options is _not_ strictly an Ada compiler. You need -gnato and
-fstack-check to get strict Ada compliance.

-gnato tells GNAT to check for constraint errors. It is left off by
default for historical reasons; the initial reason, back in the dawn
of GNAT, was the notion that such checks would make the code "too
slow". Many have argued that was a bad idea (and I agree :), but
AdaCore is not going to change the default now.

The other lesson here is that you _must_ read the user's guide for a
compiler before using it for serious work (or even non-serious work).
In particular, you _must_ understand the compiler options, and
deliberately decide whether to keep the defaults or override them.

-- 
-- Stephe



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

* Re: Newbie question
  2007-11-24 16:49 ` Stephen Leake
@ 2007-11-24 17:08   ` Peter C. Chapin
  2007-11-25 19:25     ` Stephen Leake
  2007-11-29  0:46   ` Robert A Duff
  1 sibling, 1 reply; 62+ messages in thread
From: Peter C. Chapin @ 2007-11-24 17:08 UTC (permalink / raw)


Stephen Leake wrote:

> -gnato tells GNAT to check for constraint errors. It is left off by
> default for historical reasons...

Wouldn't it be more accurate to say that -gnato checks for constraint
errors due specifically to numeric overflows? Even without -gnato
violation of subtype constraints (for example) are still checked.

Peter



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

* Re: Newbie question
  2007-11-24 17:08   ` Peter C. Chapin
@ 2007-11-25 19:25     ` Stephen Leake
  0 siblings, 0 replies; 62+ messages in thread
From: Stephen Leake @ 2007-11-25 19:25 UTC (permalink / raw)


"Peter C. Chapin" <pchapin@sover.net> writes:

> Stephen Leake wrote:
>
>> -gnato tells GNAT to check for constraint errors. It is left off by
>> default for historical reasons...
>
> Wouldn't it be more accurate to say that -gnato checks for constraint
> errors due specifically to numeric overflows? 

Yes.

> Even without -gnato violation of subtype constraints (for example)
> are still checked.
>
> Peter

-- 
-- Stephe



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

* Re: Newbie question
  2007-11-24 16:49 ` Stephen Leake
  2007-11-24 17:08   ` Peter C. Chapin
@ 2007-11-29  0:46   ` Robert A Duff
  1 sibling, 0 replies; 62+ messages in thread
From: Robert A Duff @ 2007-11-29  0:46 UTC (permalink / raw)


Stephen Leake <stephen_leake@stephe-leake.org> writes:

> However, as has been pointed out many times here, GNAT with the
> default options is _not_ strictly an Ada compiler. You need -gnato and
> -fstack-check to get strict Ada compliance.

Right.  You should also use -gnata to turn on assertions.

- Bob



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

* Newbie question
@ 2009-03-12 13:29 Olivier Scalbert
  2009-03-12 13:48 ` Ludovic Brenta
                   ` (4 more replies)
  0 siblings, 5 replies; 62+ messages in thread
From: Olivier Scalbert @ 2009-03-12 13:29 UTC (permalink / raw)


Hello,

I start learning Ada and I try to define types for a chess engine.

I have create some "obvious" types:

     type Color_T is (White, Black);

     type PieceType_T is (Pawn, Knight, Bishop, Rook, Queen, King);

     type Piece_T is record
         Color: Color_T;
         PieceType: PieceType_T;
     end record;


Now, I want to create an array of 64 squares representing the chess 
board. A square should contain nothing or a Piece_T

I have tried:

     type Board_T is array(1..64) of Piece_T;

But I can not have an empty square !

What is the best way of doing that ?

Thanks,

Olivier



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

* Re: Newbie question
  2009-03-12 13:29 Olivier Scalbert
@ 2009-03-12 13:48 ` Ludovic Brenta
  2009-03-12 14:16   ` Olivier Scalbert
  2009-03-12 15:07   ` Robert A Duff
  2009-03-12 17:16 ` Georg Bauhaus
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 62+ messages in thread
From: Ludovic Brenta @ 2009-03-12 13:48 UTC (permalink / raw)


On Mar 12, 2:29 pm, Olivier Scalbert <olivier.scalb...@algosyn.com>
wrote:
> Hello,
>
> I start learning Ada and I try to define types for a chess engine.
>
> I have create some "obvious" types:
>
>      type Color_T is (White, Black);
>
>      type PieceType_T is (Pawn, Knight, Bishop, Rook, Queen, King);
>
>      type Piece_T is record
>          Color: Color_T;
>          PieceType: PieceType_T;
>      end record;
>
> Now, I want to create an array of 64 squares representing the chess
> board. A square should contain nothing or a Piece_T
>
> I have tried:
>
>      type Board_T is array(1..64) of Piece_T;
>
> But I can not have an empty square !
>
> What is the best way of doing that ?
>
> Thanks,
>
> Olivier

Solution 1: a variant record:

type Square_T (Empty : Boolean) is record
   case Empty is
      when True => null;
      when False => Piece : Piece_T;
   end case;
end record;

type Board_T is array (1 .. 8, 1 .. 8) of Square_T;

Solution 2: merge the Boolean directly into Piece_T:

type Piece_T (Present : Boolean) is record
   case Present is
      when True =>
         Color : Color_T;
         Piece_Type : Piece_Type_T;
      when False =>
         null;
   end case;
end record;

Solution 3: introduce a new value for Piece_Type_T:

type Piece_Type_T is (None, Pawn, Knight, Bishop, Rook, Queen, King);

I don't know which is the best solution; perhaps you'd like to try
them all and see how well they integrate with the algorithms.  I think
Solution 3 is the most error-prone, though.

--
Ludovic Brenta;



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

* Re: Newbie question
  2009-03-12 13:48 ` Ludovic Brenta
@ 2009-03-12 14:16   ` Olivier Scalbert
  2009-03-12 14:31     ` Ludovic Brenta
  2009-03-12 14:32     ` stefan-lucks
  2009-03-12 15:07   ` Robert A Duff
  1 sibling, 2 replies; 62+ messages in thread
From: Olivier Scalbert @ 2009-03-12 14:16 UTC (permalink / raw)


Ludovic Brenta wrote:

> Solution 1: a variant record:
> 
> type Square_T (Empty : Boolean) is record
>    case Empty is
>       when True => null;
>       when False => Piece : Piece_T;
>    end case;
> end record;
> 
> type Board_T is array (1 .. 8, 1 .. 8) of Square_T;
> 
> Solution 2: merge the Boolean directly into Piece_T:
> 
> type Piece_T (Present : Boolean) is record
>    case Present is
>       when True =>
>          Color : Color_T;
>          Piece_Type : Piece_Type_T;
>       when False =>
>          null;
>    end case;
> end record;
> 
> Solution 3: introduce a new value for Piece_Type_T:
> 
> type Piece_Type_T is (None, Pawn, Knight, Bishop, Rook, Queen, King);
> 
> I don't know which is the best solution; perhaps you'd like to try
> them all and see how well they integrate with the algorithms.  I think
> Solution 3 is the most error-prone, though.
> 
> --
> Ludovic Brenta;

3 solutions ! Thanks Ludovic.

I like the first two solutions. With solution 3, you can have an empty 
square (None) with a color.

Olivier



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

* Re: Newbie question
  2009-03-12 14:16   ` Olivier Scalbert
@ 2009-03-12 14:31     ` Ludovic Brenta
  2009-03-12 14:32     ` stefan-lucks
  1 sibling, 0 replies; 62+ messages in thread
From: Ludovic Brenta @ 2009-03-12 14:31 UTC (permalink / raw)


On Mar 12, 3:16 pm, Olivier Scalbert <olivier.scalb...@algosyn.com>
wrote:
> Ludovic Brenta wrote:
> > Solution 1: a variant record:
>
> > type Square_T (Empty : Boolean) is record
> >    case Empty is
> >       when True => null;
> >       when False => Piece : Piece_T;
> >    end case;
> > end record;
>
> > type Board_T is array (1 .. 8, 1 .. 8) of Square_T;
>
> > Solution 2: merge the Boolean directly into Piece_T:
>
> > type Piece_T (Present : Boolean) is record
> >    case Present is
> >       when True =>
> >          Color : Color_T;
> >          Piece_Type : Piece_Type_T;
> >       when False =>
> >          null;
> >    end case;
> > end record;
>
> > Solution 3: introduce a new value for Piece_Type_T:
>
> > type Piece_Type_T is (None, Pawn, Knight, Bishop, Rook, Queen, King);
>
> > I don't know which is the best solution; perhaps you'd like to try
> > them all and see how well they integrate with the algorithms.  I think
> > Solution 3 is the most error-prone, though.
>
> 3 solutions ! Thanks Ludovic.
>
> I like the first two solutions. With solution 3, you can have an empty
> square (None) with a color.

Come to think of it, you'll want to add default values to the
discriminants in solutions 1 and 2:

type Square_T (Empty : Boolean := True) is record ...  end record;

or

type Piece_T (Present : Boolean := False) is record ... end record;

This makes it possible to change the value of the discriminant square
by assigning an aggregate, e.g.

Board (5, 5) := -- Solution 1
  Square_T'(Empty => False, Piece => (Color => Black, Piece_Type =>
Pawn));
Board (5, 5) := -- Solution 2
  Piece_T'(Present => True, Color => Black, Piece_Type => Pawn);

I think I like solution 2 better, but then I'd rename Piece_T into
Square_T.

--
Ludovic Brenta.



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

* Re: Newbie question
  2009-03-12 14:16   ` Olivier Scalbert
  2009-03-12 14:31     ` Ludovic Brenta
@ 2009-03-12 14:32     ` stefan-lucks
  2009-03-12 14:36       ` Ludovic Brenta
  2009-03-12 15:03       ` Jacob Sparre Andersen
  1 sibling, 2 replies; 62+ messages in thread
From: stefan-lucks @ 2009-03-12 14:32 UTC (permalink / raw)


On Thu, 12 Mar 2009, Olivier Scalbert wrote:

> Ludovic Brenta wrote:
> 
> > Solution 2: merge the Boolean directly into Piece_T:
> > 
> > type Piece_T (Present : Boolean) is record
> >    case Present is
> >       when True =>
> >          Color : Color_T;
> >          Piece_Type : Piece_Type_T;
> >       when False =>
> >          null;
> >    end case;
> > end record;

Solution 2a: Use an enumeration:

type Color_T is (Black, White, None);

type Piece_T(Color: Color_T) is 
  record
    case Color is
      when White => 
        White_Piece: Piece_Type_T;
      when Black => 
        Black_Piece: Piece_Type_T;
      when None =>
        null;
    end case;
  end record;

So long

Stefan


-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------




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

* Re: Newbie question
  2009-03-12 14:32     ` stefan-lucks
@ 2009-03-12 14:36       ` Ludovic Brenta
  2009-03-12 17:14         ` stefan-lucks
  2009-03-12 15:03       ` Jacob Sparre Andersen
  1 sibling, 1 reply; 62+ messages in thread
From: Ludovic Brenta @ 2009-03-12 14:36 UTC (permalink / raw)


On Mar 12, 3:32 pm, stefan-lu...@see-the.signature wrote:
> On Thu, 12 Mar 2009, Olivier Scalbert wrote:
> > Ludovic Brenta wrote:
>
> > > Solution 2: merge the Boolean directly into Piece_T:
>
> > > type Piece_T (Present : Boolean) is record
> > >    case Present is
> > >       when True =>
> > >          Color : Color_T;
> > >          Piece_Type : Piece_Type_T;
> > >       when False =>
> > >          null;
> > >    end case;
> > > end record;
>
> Solution 2a: Use an enumeration:
>
> type Color_T is (Black, White, None);
>
> type Piece_T(Color: Color_T) is
>   record
>     case Color is
>       when White =>
>         White_Piece: Piece_Type_T;
>       when Black =>
>         Black_Piece: Piece_Type_T;
>       when None =>
>         null;
>     end case;
>   end record;

The problem with this is that you'd then need two code paths for
Black_Piece and White_Piece, every time. To overcome this, here is
solution 2a1:

type Square_T (Color : Color_T := None) is record
   case Color is
      when None => null;
      when Black | White => Piece_Type : Piece_Type_T;
   end case;
end record;

--
Ludovic Brenta.



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

* Re: Newbie question
  2009-03-12 14:32     ` stefan-lucks
  2009-03-12 14:36       ` Ludovic Brenta
@ 2009-03-12 15:03       ` Jacob Sparre Andersen
  1 sibling, 0 replies; 62+ messages in thread
From: Jacob Sparre Andersen @ 2009-03-12 15:03 UTC (permalink / raw)


stefan-lucks@see-the.signature wrote:

> Solution 2a: Use an enumeration:
> 
> type Color_T is (Black, White, None);
> 
> type Piece_T(Color: Color_T) is 
>   record
>     case Color is
>       when White => 
>         White_Piece: Piece_Type_T;
>       when Black => 
>         Black_Piece: Piece_Type_T;
>       when None =>
>         null;
>     end case;
>   end record;

Solution 2b: With defaults and a common name for pieces:

   type Square_Colour is (Black, White, None);

   type Square (Colour : Square_Colour := None) is
      record
         when Black | White =>
            Piece : Piece_Type_T; -- "Piece_Type_T" is (IMO) an ugly identifier
         when None =>
            null;
      end record;

Greetings,

Jacob
-- 
"This page inadvertently left blank."



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

* Re: Newbie question
  2009-03-12 13:48 ` Ludovic Brenta
  2009-03-12 14:16   ` Olivier Scalbert
@ 2009-03-12 15:07   ` Robert A Duff
  1 sibling, 0 replies; 62+ messages in thread
From: Robert A Duff @ 2009-03-12 15:07 UTC (permalink / raw)


Ludovic Brenta <ludovic@ludovic-brenta.org> writes:

> Solution 3: introduce a new value for Piece_Type_T:
>
> type Piece_Type_T is (None, Pawn, Knight, Bishop, Rook, Queen, King);
>
> I don't know which is the best solution; perhaps you'd like to try
> them all and see how well they integrate with the algorithms.  I think
> Solution 3 is the most error-prone, though.

A variation on 3 is not error prone:

    type Optional_Piece_Kind is 
        (None, Pawn, Knight, Bishop, Rook, Queen, King);
    subtype Piece_Kind is Optional_Piece_Kind range
        Optional_Piece_Kind'Succ(None)..Optional_Piece_Kind'Last;
    
    type Square(Kind: Optional_Piece_Kind is := None) is
        record
            case Kind is
                when None => null;
                when Piece_Kind => Color: ...;
            end case;
        end record;

    type Rank is range 1..8;
    type File is new Character range 'A'..'H';
    -- Maybe I've got this backwards???
    type Board is array (Rank, File) of Square;

As somebody said, you will want a default value for the discriminant, in
all these variations.  Having a default has the odd property that it
allows you to change the discriminant by a whole-record assignment.
This oddity often confuses beginners to Ada.

- Bob



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

* Re: Newbie question
  2009-03-12 14:36       ` Ludovic Brenta
@ 2009-03-12 17:14         ` stefan-lucks
  2009-03-12 18:29           ` Adam Beneschan
  0 siblings, 1 reply; 62+ messages in thread
From: stefan-lucks @ 2009-03-12 17:14 UTC (permalink / raw)


[-- Attachment #1: Type: TEXT/PLAIN, Size: 1043 bytes --]

> > type Piece_T(Color: Color_T) is
> > � record
> > � � case Color is
> > � � � when White =>
> > � � � � White_Piece: Piece_Type_T;
> > � � � when Black =>
> > � � � � Black_Piece: Piece_Type_T;
> > � � � when None =>
> > � � � � null;
> > � � end case;
> > � end record;
> 
> The problem with this is that you'd then need two code paths for
> Black_Piece and White_Piece, every time. 

Right. Actually, I anticipated that you would *want* two code paths for 
the black and for the white pieces. Else, your approach the approach 
below is better.

> To overcome this, here is solution 2a1:

> type Square_T (Color : Color_T := None) is record
>    case Color is
>       when None => null;
>       when Black | White => Piece_Type : Piece_Type_T;
>    end case;
> end record;

-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------

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

* Re: Newbie question
  2009-03-12 13:29 Olivier Scalbert
  2009-03-12 13:48 ` Ludovic Brenta
@ 2009-03-12 17:16 ` Georg Bauhaus
  2009-03-13  1:59 ` tmoran
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 62+ messages in thread
From: Georg Bauhaus @ 2009-03-12 17:16 UTC (permalink / raw)


Olivier Scalbert schrieb:

> But I can not have an empty square !

You can have an empty square. Just say so :-)
Yet another option might be this one:


   type Color_T is (White, Black, Transparent);

   type PieceType_T is
     (Pawn, Knight, Bishop, Rook, Queen, King, Ghost);

   type Piece_T is record
      Color: Color_T;
      PieceType: PieceType_T;
   end record;

   type Square_Index is range 1 .. 64;
   type Board_T is array(Square_Index) of Piece_T;

   Empty_Square: constant Piece_T :=
     (Color => Transparent,
      PieceType => Ghost);


The distinction between empty square or figure is thus
moved from a variant record to testing for a special,
colorless ghost.



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

* Re: Newbie question
  2009-03-12 17:14         ` stefan-lucks
@ 2009-03-12 18:29           ` Adam Beneschan
  0 siblings, 0 replies; 62+ messages in thread
From: Adam Beneschan @ 2009-03-12 18:29 UTC (permalink / raw)


On Mar 12, 10:14 am, stefan-lu...@see-the.signature wrote:
> > > type Piece_T(Color: Color_T) is
> > >   record
> > >     case Color is
> > >       when White =>
> > >         White_Piece: Piece_Type_T;
> > >       when Black =>
> > >         Black_Piece: Piece_Type_T;
> > >       when None =>
> > >         null;
> > >     end case;
> > >   end record;
>
> > The problem with this is that you'd then need two code paths for
> > Black_Piece and White_Piece, every time.
>
> Right. Actually, I anticipated that you would *want* two code paths for
> the black and for the white pieces.

I don't see why... I'd anticipate writing a subprogram like

   function Compute_Best_Move_For (Color: Color_T) return Move_T;

[more accurately, instead of Color_T, we'd use a subtype that is a
subrange of Color_T that allows only Black and White].  Now having two
different paths would be an utter nuisance.  Aside from the small
detail that the pawns move in different directions, the algorithm
would be exactly the same for both colors.

In fact, I'd think most of the algorithms you would want to write that
pertain to one particular player would work exactly the same for Black
and White, except for pawn direction, and that can be dealt with by
setting up some variable with value +1 for White and -1 for Black (or
vice versa).

                                -- Adam



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

* Re: Newbie question
  2009-03-12 13:29 Olivier Scalbert
  2009-03-12 13:48 ` Ludovic Brenta
  2009-03-12 17:16 ` Georg Bauhaus
@ 2009-03-13  1:59 ` tmoran
  2009-03-15 13:46 ` Olivier Scalbert
  2009-03-21 18:08 ` Olivier Scalbert
  4 siblings, 0 replies; 62+ messages in thread
From: tmoran @ 2009-03-13  1:59 UTC (permalink / raw)


On Mar 12, 5:29 am, Olivier Scalbert <olivier.scalb...@algosyn.com>
wrote:
> Hello,
>
> I start learning Ada and I try to define types for a chess engine.
>
> I have create some "obvious" types:
>
>      type Color_T is (White, Black);
>
>      type PieceType_T is (Pawn, Knight, Bishop, Rook, Queen, King);
>
>      type Piece_T is record
>          Color: Color_T;
>          PieceType: PieceType_T;
>      end record;
>
> Now, I want to create an array of 64 squares representing the chess
> board. A square should contain nothing or a Piece_T
>
> I have tried:
>
>      type Board_T is array(1..64) of Piece_T;
>
> But I can not have an empty square !
>
> What is the best way of doing that ?
>
> Thanks,
>
> Olivier

A piece in a game is not so much a physical object as a characteristic
of a particular square.  You don't want to say for instance
  Synod : array(1 .. 5) of (Color=>White, Kind=>Bishop);
  ...
  Board(G,3) := Synod(4);
So how about
  type Occupants is (Empty, Black_King, Black_Queen, Black_Bishop,
                   .... White_King, White_Queen, .... White_Pawn);
  subtype Blacks is Occupants range (Black King .. Black_Pawn);
  subtype Whites is Occupants range (White King .. White_Pawn);
  Board : array(Files, Ranks) of Occupants;
then your code can say things like
  if Board(G,4) in Whites then ...
  if Board(G, 5) = Black_King and Board(G,6) = Empty then ...



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

* Re: Newbie question
  2009-03-12 13:29 Olivier Scalbert
                   ` (2 preceding siblings ...)
  2009-03-13  1:59 ` tmoran
@ 2009-03-15 13:46 ` Olivier Scalbert
  2009-03-21 18:08 ` Olivier Scalbert
  4 siblings, 0 replies; 62+ messages in thread
From: Olivier Scalbert @ 2009-03-15 13:46 UTC (permalink / raw)


Olivier Scalbert wrote:
> Hello,
> 
> I start learning Ada and I try to define types for a chess engine.
> 
> I have create some "obvious" types:
> 
>     type Color_T is (White, Black);
> 
>     type PieceType_T is (Pawn, Knight, Bishop, Rook, Queen, King);
> 
>     type Piece_T is record
>         Color: Color_T;
>         PieceType: PieceType_T;
>     end record;
> 
> 
> Now, I want to create an array of 64 squares representing the chess 
> board. A square should contain nothing or a Piece_T
> 
> I have tried:
> 
>     type Board_T is array(1..64) of Piece_T;
> 
> But I can not have an empty square !
> 
> What is the best way of doing that ?
> 
> Thanks,
> 
> Olivier

Thanks all of you for your interesting answers !

Olivier



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

* Re: Newbie question
  2009-03-12 13:29 Olivier Scalbert
                   ` (3 preceding siblings ...)
  2009-03-15 13:46 ` Olivier Scalbert
@ 2009-03-21 18:08 ` Olivier Scalbert
  2009-03-21 18:22   ` (see below)
  4 siblings, 1 reply; 62+ messages in thread
From: Olivier Scalbert @ 2009-03-21 18:08 UTC (permalink / raw)


Hi all,

I have write some more chess code, and I have another question !

Code can be browsed there:
http://scalbert.dyndns.org/adachess/

Inside board.adb there is a procedure:

Move_King(Board: Board_T;
           Color: Color_T;
           Moves_List: in out Moves_List_T;
           From: Position_T) is

Inside this procedure, I have something strange, line 39.

if Col > 1 then -- ERROR should be From.Col
    ...

should be:

if From.Col > 1 then
    ....

I do not understand how this code can compile, because Col is not 
defined there. Perhaps it is because of the way I call it ?

This procedure is called from Generate_All_Moves:
     ...
     when King   => Move_King(Board, Color, Moves_List, (col, row));
     ...

I must have done a big mistake (my fist program in Ada ...), but I do 
not know where. I am sure you will have a good explanation !

Thanks to help me,

Olivier



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

* Re: Newbie question
  2009-03-21 18:08 ` Olivier Scalbert
@ 2009-03-21 18:22   ` (see below)
  2009-03-21 18:29     ` Olivier Scalbert
  0 siblings, 1 reply; 62+ messages in thread
From: (see below) @ 2009-03-21 18:22 UTC (permalink / raw)


On 21/03/2009 18:08, in article 49c52d2f$0$2856$ba620e4c@news.skynet.be,
"Olivier Scalbert" <olivier.scalbert@algosyn.com> wrote:

> Hi all,
> 
> I have write some more chess code, and I have another question !
> 
> Code can be browsed there:
> http://scalbert.dyndns.org/adachess/
> 
> Inside board.adb there is a procedure:
> 
> Move_King(Board: Board_T;
>            Color: Color_T;
>            Moves_List: in out Moves_List_T;
>            From: Position_T) is
> 
> Inside this procedure, I have something strange, line 39.
> 
> if Col > 1 then -- ERROR should be From.Col
>     ...
> 
> should be:
> 
> if From.Col > 1 then
>     ....
> 
> I do not understand how this code can compile, because Col is not
> defined there. Perhaps it is because of the way I call it ?
> 

You said: Ada.Text_IO; so you are evaluating Ada.Text_IO.Col > 1
-- 
Bill Findlay
<surname><forename> chez blueyonder.co.uk





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

* Re: Newbie question
  2009-03-21 18:22   ` (see below)
@ 2009-03-21 18:29     ` Olivier Scalbert
  2009-03-21 18:36       ` Georg Bauhaus
                         ` (2 more replies)
  0 siblings, 3 replies; 62+ messages in thread
From: Olivier Scalbert @ 2009-03-21 18:29 UTC (permalink / raw)


  > You said: Ada.Text_IO; so you are evaluating Ada.Text_IO.Col > 1
Ooops, nice catch !

I think I will remove all my "use" !

Olivier



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

* Re: Newbie question
  2009-03-21 18:29     ` Olivier Scalbert
@ 2009-03-21 18:36       ` Georg Bauhaus
  2009-03-21 18:39         ` Olivier Scalbert
  2009-03-21 18:39       ` Jeffrey R. Carter
  2009-03-23  8:24       ` Jean-Pierre Rosen
  2 siblings, 1 reply; 62+ messages in thread
From: Georg Bauhaus @ 2009-03-21 18:36 UTC (permalink / raw)


Olivier Scalbert wrote:
>  > You said: Ada.Text_IO; so you are evaluating Ada.Text_IO.Col > 1
> Ooops, nice catch !
> 
> I think I will remove all my "use" !

That's a bit quick, I should think.  Another option
is to place "use" in context, use renamings, or
comment "use" temporarily in order to catch
overloaded names.



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

* Re: Newbie question
  2009-03-21 18:29     ` Olivier Scalbert
  2009-03-21 18:36       ` Georg Bauhaus
@ 2009-03-21 18:39       ` Jeffrey R. Carter
  2009-03-23  8:24       ` Jean-Pierre Rosen
  2 siblings, 0 replies; 62+ messages in thread
From: Jeffrey R. Carter @ 2009-03-21 18:39 UTC (permalink / raw)


Olivier Scalbert wrote:
> 
> I think I will remove all my "use" !

That's a good idea for a beginner.

-- 
Jeff Carter
"Hold your temper. Count ten.... Now let 'er go.
You got a good aim."
Never Give a Sucker an Even Break
105



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

* Re: Newbie question
  2009-03-21 18:36       ` Georg Bauhaus
@ 2009-03-21 18:39         ` Olivier Scalbert
  2009-03-22 12:40           ` (see below)
  0 siblings, 1 reply; 62+ messages in thread
From: Olivier Scalbert @ 2009-03-21 18:39 UTC (permalink / raw)


Yes I agree.
But I should have use column instead of col ...


Georg Bauhaus wrote:
> Olivier Scalbert wrote:
>>  > You said: Ada.Text_IO; so you are evaluating Ada.Text_IO.Col > 1
>> Ooops, nice catch !
>>
>> I think I will remove all my "use" !
> 
> That's a bit quick, I should think.  Another option
> is to place "use" in context, use renamings, or
> comment "use" temporarily in order to catch
> overloaded names.



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

* Re: Newbie question
  2009-03-21 18:39         ` Olivier Scalbert
@ 2009-03-22 12:40           ` (see below)
  2009-03-22 13:19             ` Olivier Scalbert
  0 siblings, 1 reply; 62+ messages in thread
From: (see below) @ 2009-03-22 12:40 UTC (permalink / raw)


On 21/03/2009 18:39, in article 49c5346d$0$2860$ba620e4c@news.skynet.be,
"Olivier Scalbert" <olivier.scalbert@algosyn.com> wrote:

>Georg Bauhaus wrote:
>> Olivier Scalbert wrote:
>>> I think I will remove all my "use" !
> 
>> That's a bit quick, I should think.  Another option
>> is to place "use" in context, use renamings, or
>> comment "use" temporarily in order to catch
>> overloaded names.

> Yes I agree.
> But I should have use column instead of col ...

That's the right answer. 8-)

-- 
Bill Findlay
<surname><forename> chez blueyonder.co.uk





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

* Re: Newbie question
  2009-03-22 12:40           ` (see below)
@ 2009-03-22 13:19             ` Olivier Scalbert
  0 siblings, 0 replies; 62+ messages in thread
From: Olivier Scalbert @ 2009-03-22 13:19 UTC (permalink / raw)


Ooops, Column instead of Col !
;-)

(see below) wrote:
> On 21/03/2009 18:39, in article 49c5346d$0$2860$ba620e4c@news.skynet.be,
> "Olivier Scalbert" <olivier.scalbert@algosyn.com> wrote:
> 
>> Georg Bauhaus wrote:
>>> Olivier Scalbert wrote:
>>>> I think I will remove all my "use" !
>>> That's a bit quick, I should think.  Another option
>>> is to place "use" in context, use renamings, or
>>> comment "use" temporarily in order to catch
>>> overloaded names.
> 
>> Yes I agree.
>> But I should have use column instead of col ...
> 
> That's the right answer. 8-)
> 



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

* Re: Newbie question
  2009-03-21 18:29     ` Olivier Scalbert
  2009-03-21 18:36       ` Georg Bauhaus
  2009-03-21 18:39       ` Jeffrey R. Carter
@ 2009-03-23  8:24       ` Jean-Pierre Rosen
  2 siblings, 0 replies; 62+ messages in thread
From: Jean-Pierre Rosen @ 2009-03-23  8:24 UTC (permalink / raw)


Olivier Scalbert a �crit :
>  > You said: Ada.Text_IO; so you are evaluating Ada.Text_IO.Col > 1
> Ooops, nice catch !
> 
> I think I will remove all my "use" !
> 
> Olivier
Don't go from one extreme to another.

The right thing to do is to have use clauses restricted to the innermost
scope where they are useful.

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



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

end of thread, other threads:[~2009-03-23  8:24 UTC | newest]

Thread overview: 62+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-18 11:26 Newbie question Francisco J. Montoya
2005-07-18 13:14 ` Martin Dowie
2005-07-18 13:51   ` Alex R. Mosteo
2005-07-18 20:27     ` Martin Dowie
2005-07-18 15:28 ` Jeffrey Carter
2005-07-18 17:40 ` Martin Krischik
  -- strict thread matches above, loose matches on Subject: below --
2009-03-12 13:29 Olivier Scalbert
2009-03-12 13:48 ` Ludovic Brenta
2009-03-12 14:16   ` Olivier Scalbert
2009-03-12 14:31     ` Ludovic Brenta
2009-03-12 14:32     ` stefan-lucks
2009-03-12 14:36       ` Ludovic Brenta
2009-03-12 17:14         ` stefan-lucks
2009-03-12 18:29           ` Adam Beneschan
2009-03-12 15:03       ` Jacob Sparre Andersen
2009-03-12 15:07   ` Robert A Duff
2009-03-12 17:16 ` Georg Bauhaus
2009-03-13  1:59 ` tmoran
2009-03-15 13:46 ` Olivier Scalbert
2009-03-21 18:08 ` Olivier Scalbert
2009-03-21 18:22   ` (see below)
2009-03-21 18:29     ` Olivier Scalbert
2009-03-21 18:36       ` Georg Bauhaus
2009-03-21 18:39         ` Olivier Scalbert
2009-03-22 12:40           ` (see below)
2009-03-22 13:19             ` Olivier Scalbert
2009-03-21 18:39       ` Jeffrey R. Carter
2009-03-23  8:24       ` Jean-Pierre Rosen
2007-11-23 13:22 Sir Chewbury Gubbins
2007-11-23 14:01 ` Sir Chewbury Gubbins
2007-11-24 16:49 ` Stephen Leake
2007-11-24 17:08   ` Peter C. Chapin
2007-11-25 19:25     ` Stephen Leake
2007-11-29  0:46   ` Robert A Duff
2005-07-03 17:58 newbie question e.coli
2005-07-03 18:32 ` Dmitry A. Kazakov
2004-08-04  6:42 Newbie Question leke
2004-08-04  8:55 ` Frank
2004-08-04  9:51 ` Martin Dowie
2001-12-24 13:52 Newbie question Jasbinder S  Uppal
2001-12-24 20:06 ` Michal Nowak
2001-12-24 21:13   ` martin.m.dowie
2001-12-25 12:36     ` Michal Nowak
2001-12-27 14:25       ` Alfred Hilscher
2001-12-29 21:54         ` Michal Nowak
2001-12-31 17:51           ` Jasbinder S Uppal
2002-01-01 21:26             ` Michal Nowak
2000-05-25  0:00 olsonm76
2000-05-26  0:00 ` Robert Dewar
1999-03-18  0:00 newbie question Kenneth Lee
1999-03-18  0:00 ` Andreas Winckler
1999-03-19  0:00   ` Kenneth Lee
1999-03-19  0:00     ` Michael F Brenner
1999-03-19  0:00       ` ELMO
1999-03-21  0:00       ` Matthew Heaney
1999-03-18  0:00 ` Tom Moran
1999-03-18  0:00   ` Kenneth Lee
1999-03-18  0:00     ` Nick Roberts
1999-03-19  0:00 ` robert_dewar
1999-03-19  0:00 ` Michael F Brenner
1999-03-19  0:00   ` Nick Roberts
1999-03-20  0:00     ` Nick Roberts

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