comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: I'm Stumped ...
Date: 1997/04/27
Date: 1997-04-27T00:00:00+00:00	[thread overview]
Message-ID: <dewar.862168823@merv> (raw)
In-Reply-To: 33638FBE.715C@usa.net


Ben Carter asks:

  Is it possible to take a string with the value :
     '123'
  and turn it into the integer 123?

  Any Help would be appreciated :)
  Thanks For your time ...

First, it is trivial to write code that does this, just write a loop that
starts with zero and traverses the string from the back, multiplying what
you have by 10 and adding in the next digit. It's just 2 or 3 lines of code.

Second, let's see if we can learn how to find this in the RM. Bob Duff
did a great job of the index, so we start from there. Look up string:

  String   3.6.3(4), A.1(37)
  string type   3.6.3(1)

Hmmm! not much to be found there, well we are trying to convert from
string to integer, so perhaps look up Integer:

   Integer   3.5.4(11), 3.5.4(21), A.1(12)

OK, off we go to 3.5.4. Now what we want is operations on integer types,
and we do not find it in 3.5.4, but a little looking in the table of
contents shows us where we are:

   3.5 Scalar Types
       3.5.1 Enumeration Types
       3.5.2 Character Types
       3.5.3 Boolean Types
       3.5.4 Integer Types
       3.5.5 Operations of Discrete Types
       3.5.6 Real Types
       3.5.7 Floating Point Types
       3.5.8 Operations of Floating Point Types
       3.5.9 Fixed Point Types
       3.5.10 Operations of Fixed Point Types

And ah ha! Operations of Discrete types sounds right -- the reason we did
not find anything specific on operations of integer types is that they are
grouped together with discrete types. OK, let's go visit 3.5.5:

And we find a list of attributes, let's glance through and see if there
is anything useful (in fact how about searching this section for String:

We first find Wide_Image, a little look shows us that goes the other way,
but we are getting warm, search on, also it is for Wide_String. Image is
the next hit, still not what we want.

Searching on, we hit Wide_Value -- ah ha! getting very warm, but still 
works on Wide_String, one more search, and voila!

52  S'Value
                S'Value denotes a function with the following specification:

53                  function S'Value(Arg : String)
                      return S'Base

                54   This function returns a value given an image of the
                value as a String, ignoring any leading or trailing spaces.


And there we have it, so what you are looking for is IntegerVlue. Well
it wasn't immediate (ch 3 is always tough), but we found it. I find it
tremendously useful to have an ASCII version of the RM that I can just
search around with in the editor.

General note: I strongly that everyone peruse annex K of the RM, there are
lots of useful attributes there which are worth knowing about (I keep seeing
Ada 95 programmers who clearly do not know about max and min for example).





  reply	other threads:[~1997-04-27  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-28  0:00 I'm Stumped Ben Carter
1997-04-27  0:00 ` Robert Dewar [this message]
1997-04-27  0:00 ` Matthew Heaney
1997-04-28  0:00 ` Stephen Leake
1997-04-30  0:00 ` Gautier
1997-04-30  0:00   ` Mats Weber
replies disabled

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