comp.lang.ada
 help / color / mirror / Atom feed
* Beginners question
@ 2021-11-12 14:32 uq5huo...@gmail.com
  2021-11-12 15:24 ` Niklas Holsti
  0 siblings, 1 reply; 7+ messages in thread
From: uq5huo...@gmail.com @ 2021-11-12 14:32 UTC (permalink / raw)


Hi, 

I'm beginning to play with Ada, and run into this

with Ada.Text_IO; use Ada.Text_IO;
procedure Learn is
   subtype Alphabet is Character range 'A' .. 'Z';
begin
   Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last);
end Learn;

Now I want to play a bit with the code ... and this fails and I don't get why and how to solve. 

Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last-1);
or 
Put_Line ("Learning Ada from " & Alphabet'First & " to " & (Alphabet'Last-1));

Anyone more expirienced can explain this to my, please?

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

* Re: Beginners question
  2021-11-12 14:32 Beginners question uq5huo...@gmail.com
@ 2021-11-12 15:24 ` Niklas Holsti
  2021-11-12 15:44   ` uq5huo...@gmail.com
  2021-11-12 15:44   ` uq5huo...@gmail.com
  0 siblings, 2 replies; 7+ messages in thread
From: Niklas Holsti @ 2021-11-12 15:24 UTC (permalink / raw)


On 2021-11-12 16:32, uq5huo...@gmail.com wrote:
> Hi,
> 
> I'm beginning to play with Ada, and run into this
> 
> with Ada.Text_IO; use Ada.Text_IO;
> procedure Learn is
>     subtype Alphabet is Character range 'A' .. 'Z';
> begin
>     Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last);
> end Learn;
> 
> Now I want to play a bit with the code ... and this fails and I don't get why and how to solve.
> 
> Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last-1);
> or
> Put_Line ("Learning Ada from " & Alphabet'First & " to " & (Alphabet'Last-1));
> 
> Anyone more expirienced can explain this to my, please?


The Character type is not an integer type (unlike "char" in C), so you 
cannot subtract 1 from a Character (or an Alphabet value). Character is 
an enumeration type in Ada.

To get the Alphabet value immediately preceding Alphabet'Last, use the 
Pred ("predecessor") attribute function:

    Alphabet'Pred (Alphabet'Last)

If you need to take larger strides in the Alphabet enumeration, you can 
use the Pos and Val attribute functions. Pos returns the "position 
number" of its argument, and that is an integer. Val performs the 
opposite mapping. For example, to get the Alphabet value that is three 
positions before Alphabet'Last, you can do

    Alphabet'Val (Alphabet'Pos (Alphabet'Last) - 3)

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

* Re: Beginners question
  2021-11-12 15:24 ` Niklas Holsti
@ 2021-11-12 15:44   ` uq5huo...@gmail.com
  2021-11-12 15:44   ` uq5huo...@gmail.com
  1 sibling, 0 replies; 7+ messages in thread
From: uq5huo...@gmail.com @ 2021-11-12 15:44 UTC (permalink / raw)


Niklas Holsti schrieb am Freitag, 12. November 2021 um 16:24:20 UTC+1:
> On 2021-11-12 16:32, uq5huo...@gmail.com wrote: 
> > Hi, 
> > 
> > I'm beginning to play with Ada, and run into this 
> > 
> > with Ada.Text_IO; use Ada.Text_IO; 
> > procedure Learn is 
> > subtype Alphabet is Character range 'A' .. 'Z'; 
> > begin 
> > Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last); 
> > end Learn; 
> > 
> > Now I want to play a bit with the code ... and this fails and I don't get why and how to solve. 
> > 
> > Put_Line ("Learning Ada from " & Alphabet'First & " to " & Alphabet'Last-1); 
> > or 
> > Put_Line ("Learning Ada from " & Alphabet'First & " to " & (Alphabet'Last-1)); 
> > 
> > Anyone more expirienced can explain this to my, please?
> The Character type is not an integer type (unlike "char" in C), so you 
> cannot subtract 1 from a Character (or an Alphabet value). Character is 
> an enumeration type in Ada. 
> 
> To get the Alphabet value immediately preceding Alphabet'Last, use the 
> Pred ("predecessor") attribute function: 
> 
> Alphabet'Pred (Alphabet'Last) 
> 
> If you need to take larger strides in the Alphabet enumeration, you can 
> use the Pos and Val attribute functions. Pos returns the "position 
> number" of its argument, and that is an integer. Val performs the 
> opposite mapping. For example, to get the Alphabet value that is three 
> positions before Alphabet'Last, you can do 
> 
> Alphabet'Val (Alphabet'Pos (Alphabet'Last) - 3)

Dear Niklas, 
thanks for the explanation. So I run into the strong typing and Ada prevents me to programm C-like. I really like that. :-) 
I will read more onto the  attributes to get familar with this. 

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

* Re: Beginners question
  2021-11-12 15:24 ` Niklas Holsti
  2021-11-12 15:44   ` uq5huo...@gmail.com
@ 2021-11-12 15:44   ` uq5huo...@gmail.com
  1 sibling, 0 replies; 7+ messages in thread
From: uq5huo...@gmail.com @ 2021-11-12 15:44 UTC (permalink / raw)


Dear Niklas,
thanks for the explanation. So I run into the strong typing and Ada prevents me to programm C-like. I really like that. :-)
I will read more onto the attributes to get familar with this. 

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

* Re: Beginners question
  2002-01-02 14:44 ` Jacob Sparre Andersen
@ 2002-01-02 14:56   ` Ted Dennison
  0 siblings, 0 replies; 7+ messages in thread
From: Ted Dennison @ 2002-01-02 14:56 UTC (permalink / raw)


In article <3C331CDE.4FC536D6@nbi.dk>, Jacob Sparre Andersen says...
>
>Dave wrote:
>
>> thier wisdom have choosen Ada. I am having to write a program that
>> quite on entry of a value with of blank, in other words hitting the
>> return key. I am having trouble doing this and any help would be
>> appreciated
>
>You will need to use the package Ada.Text_IO for this
>purpose. It is described in section A.10.1 in the Language
>Reference Manual.

As a further hint, you'll probably want to concentrate on the Get_Line function.
The Get function is much harder to use effectively.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



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

* Re: Beginners question
  2001-12-17 17:05 Dave
@ 2002-01-02 14:44 ` Jacob Sparre Andersen
  2002-01-02 14:56   ` Ted Dennison
  0 siblings, 1 reply; 7+ messages in thread
From: Jacob Sparre Andersen @ 2002-01-02 14:44 UTC (permalink / raw)


Dave wrote:

> Hi all i have recently started programming and the course leaders in
> thier wisdom have choosen Ada. I am having to write a program that
> quite on entry of a value with of blank, in other words hitting the
> return key. I am having trouble doing this and any help would be
> appreciated

You will need to use the package Ada.Text_IO for this
purpose. It is described in section A.10.1 in the Language
Reference Manual.

Jacob
-- 
I �vrigt mener jeg at det er uhensigtsm�ssigt at skrive
"pipes" om kanaler i en begynderbog om Unix.



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

* Beginners question
@ 2001-12-17 17:05 Dave
  2002-01-02 14:44 ` Jacob Sparre Andersen
  0 siblings, 1 reply; 7+ messages in thread
From: Dave @ 2001-12-17 17:05 UTC (permalink / raw)


Hi all i have recently started programming and the course leaders in
thier wisdom have choosen Ada. I am having to write a program that
quite on entry of a value with of blank, in other words hitting the
return key. I am having trouble doing this and any help would be
appreciated



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

end of thread, other threads:[~2021-11-12 15:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 14:32 Beginners question uq5huo...@gmail.com
2021-11-12 15:24 ` Niklas Holsti
2021-11-12 15:44   ` uq5huo...@gmail.com
2021-11-12 15:44   ` uq5huo...@gmail.com
  -- strict thread matches above, loose matches on Subject: below --
2001-12-17 17:05 Dave
2002-01-02 14:44 ` Jacob Sparre Andersen
2002-01-02 14:56   ` Ted Dennison

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