comp.lang.ada
 help / color / mirror / Atom feed
* Characters and Numerics
@ 2001-12-05 12:03 Duke Luke
  2001-12-05 12:07 ` Lutz Donnerhacke
  2001-12-05 12:16 ` M. A. Alves
  0 siblings, 2 replies; 8+ messages in thread
From: Duke Luke @ 2001-12-05 12:03 UTC (permalink / raw)


How can I change type character to type natural??
e.g: '3' -> 3;

(The character is always a number).

Please help me.



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

* Re: Characters and Numerics
  2001-12-05 12:03 Characters and Numerics Duke Luke
@ 2001-12-05 12:07 ` Lutz Donnerhacke
  2001-12-05 12:16 ` M. A. Alves
  1 sibling, 0 replies; 8+ messages in thread
From: Lutz Donnerhacke @ 2001-12-05 12:07 UTC (permalink / raw)


* Duke Luke wrote:
>How can I change type character to type natural??
>e.g: '3' -> 3;

S'Value denotes a function with the following specification:

  function S'Value(Arg : String) return S'Base;
  
This function returns a value given an image of the value as a String,
ignoring any leading or trailing spaces.
  
For the evaluation of a call on S'Value for an enumeration subtype S, if the
sequence of characters of the parameter (ignoring leading and trailing
spaces) has the syntax of an enumeration literal and if it corresponds to a
literal of the type of S (or corresponds to the result of S'Image for a
value of the type), the result is the corresponding enumeration value;
otherwise Constraint_Error is raised. For a numeric subtype S, the
evaluation of a call on S'Value with Arg of type String is equivalent to a
call on S'Wide_Value for a corresponding Arg of type Wide_String.

=> Natural'Value ((1 => '3'));



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

* Re: Characters and Numerics
  2001-12-05 12:03 Characters and Numerics Duke Luke
  2001-12-05 12:07 ` Lutz Donnerhacke
@ 2001-12-05 12:16 ` M. A. Alves
  2001-12-05 14:58   ` Matthew Heaney
  1 sibling, 1 reply; 8+ messages in thread
From: M. A. Alves @ 2001-12-05 12:16 UTC (permalink / raw)
  To: comp.lang.ada

On 5 Dec 2001, Duke Luke wrote:
> How can I change type character to type natural??
> e.g: '3' -> 3;

Use attribute Value of the type Natural upon a String version of
the Character e.g.

  N := Natural'Value(C & "");

-- 
   ,
 M A R I O   data miner, LIACC, room 221   tel 351+226078830, ext 121
 A M A D O   Rua Campo Alegre, 823         fax 351+226003654
 A L V E S   P-4150-180 PORTO, Portugal    mob 351+939354002





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

* Re: Characters and Numerics
  2001-12-05 12:16 ` M. A. Alves
@ 2001-12-05 14:58   ` Matthew Heaney
  2001-12-05 18:55     ` Wes Groleau
  2001-12-06  0:19     ` tmoran
  0 siblings, 2 replies; 8+ messages in thread
From: Matthew Heaney @ 2001-12-05 14:58 UTC (permalink / raw)



"M. A. Alves" <maa@liacc.up.pt> wrote in message
news:mailman.1007554622.31106.comp.lang.ada@ada.eu.org...
> On 5 Dec 2001, Duke Luke wrote:
> > How can I change type character to type natural??
> > e.g: '3' -> 3;
>
> Use attribute Value of the type Natural upon a String version of
> the Character e.g.
>
>   N := Natural'Value(C & "");

Or just

   N := Character'Pos (C) - Character'Pos ('0');







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

* Re: Characters and Numerics
  2001-12-05 14:58   ` Matthew Heaney
@ 2001-12-05 18:55     ` Wes Groleau
  2001-12-05 19:24       ` Matthew Heaney
  2001-12-06  0:19     ` tmoran
  1 sibling, 1 reply; 8+ messages in thread
From: Wes Groleau @ 2001-12-05 18:55 UTC (permalink / raw)




Matthew Heaney wrote:
> 
> "M. A. Alves" <maa@liacc.up.pt> wrote in message
> news:mailman.1007554622.31106.comp.lang.ada@ada.eu.org...
> > On 5 Dec 2001, Duke Luke wrote:
> > > How can I change type character to type natural??
> > > e.g: '3' -> 3;
> >
> > Use attribute Value of the type Natural upon a String version of
> > the Character e.g.
> >
> >   N := Natural'Value(C & "");
> 
> Or just
> 
>    N := Character'Pos (C) - Character'Pos ('0');

If C = 'Z' the former will raise constraint error;
the latter will assign N a large number.


-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau



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

* Re: Characters and Numerics
  2001-12-05 18:55     ` Wes Groleau
@ 2001-12-05 19:24       ` Matthew Heaney
  2001-12-05 21:27         ` Wes Groleau
  0 siblings, 1 reply; 8+ messages in thread
From: Matthew Heaney @ 2001-12-05 19:24 UTC (permalink / raw)



"Wes Groleau" <wgroleau@usa.com> wrote in message
news:3C0E6D91.43FEE78F@usa.com...
> If C = 'Z' the former will raise constraint error;
> the latter will assign N a large number.

But he stated as a precondition that C is a digit character.  The algorithm
I provided is only guaranteed to satisfy its postcondition if the
precondition is satisfied.








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

* Re: Characters and Numerics
  2001-12-05 19:24       ` Matthew Heaney
@ 2001-12-05 21:27         ` Wes Groleau
  0 siblings, 0 replies; 8+ messages in thread
From: Wes Groleau @ 2001-12-05 21:27 UTC (permalink / raw)




Matthew Heaney wrote:
> But he stated as a precondition that C is a digit character.  The algorithm
> I provided is only guaranteed to satisfy its postcondition if the
> precondition is satisfied.

Oh, I didn't notice that precondition.  Anyway,
I think one 'value is cleaner than two 'pos and
a subtraction.  Especially if (wild guess) he's
trying to handle multiple digits and doesn't
know he can do one 'value on the whole string.  :-)

-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau



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

* Re: Characters and Numerics
  2001-12-05 14:58   ` Matthew Heaney
  2001-12-05 18:55     ` Wes Groleau
@ 2001-12-06  0:19     ` tmoran
  1 sibling, 0 replies; 8+ messages in thread
From: tmoran @ 2001-12-06  0:19 UTC (permalink / raw)


> >   N := Natural'Value(C & "");
>
> Or just
>
>    N := Character'Pos (C) - Character'Pos ('0');

or
  Digit_Value : constant array(Character range '0' .. '9') of Natural
    := (0,1,2,3,4,5,6,7,8,9);
  ...
  N := Digit_Value(C);



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

end of thread, other threads:[~2001-12-06  0:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-05 12:03 Characters and Numerics Duke Luke
2001-12-05 12:07 ` Lutz Donnerhacke
2001-12-05 12:16 ` M. A. Alves
2001-12-05 14:58   ` Matthew Heaney
2001-12-05 18:55     ` Wes Groleau
2001-12-05 19:24       ` Matthew Heaney
2001-12-05 21:27         ` Wes Groleau
2001-12-06  0:19     ` tmoran

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