comp.lang.ada
 help / color / mirror / Atom feed
* Simple library functions
@ 2004-02-12 19:37 Harald Korneliussen
  2004-02-12 19:50 ` Ed Falis
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Harald Korneliussen @ 2004-02-12 19:37 UTC (permalink / raw)


I have been trying to solve some programming excercises from
www.topcoder.com in Ada, just to compare it to Java and the other
popular languages.

One problem I keep running into is the lack of common, useful
utilities in the libraries that come with Gnat & Ada. One thing is
that I had to write my own tokenizer. That gave me the opporunity to
emulate the String.split() method in newer versions of Java, OK*. But
now I have to do an even simpler task, converting a string of digits
to an integer, and as far as I can see there is no function for this
in the standard libraries!?
I hear there is a new revision of Ada coming. I really, really hope
they adress the lack of a standard library of utillity packages
instead of adding new language features.



* Anyone want it? :-)



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

* Re: Simple library functions
  2004-02-12 19:37 Simple library functions Harald Korneliussen
@ 2004-02-12 19:50 ` Ed Falis
  2004-02-12 19:54 ` Ed Falis
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Ed Falis @ 2004-02-12 19:50 UTC (permalink / raw)


On 12 Feb 2004 11:37:36 -0800, Harald Korneliussen 
<scallassig@mailexpire.com> wrote:
> But
> now I have to do an even simpler task, converting a string of digits
> to an integer, and as far as I can see there is no function for this
> in the standard libraries!?

You mean like:

S : String := "12345";
X : Integer := S'Value;

?

- Ed



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

* Re: Simple library functions
  2004-02-12 19:37 Simple library functions Harald Korneliussen
  2004-02-12 19:50 ` Ed Falis
@ 2004-02-12 19:54 ` Ed Falis
  2004-02-12 20:54 ` Ludovic Brenta
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Ed Falis @ 2004-02-12 19:54 UTC (permalink / raw)


Whoops, should've been:

I : Integer := Integer'Value (S);

- Ed



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

* Re: Simple library functions
  2004-02-12 19:37 Simple library functions Harald Korneliussen
  2004-02-12 19:50 ` Ed Falis
  2004-02-12 19:54 ` Ed Falis
@ 2004-02-12 20:54 ` Ludovic Brenta
  2004-02-13  0:52 ` Jeffrey Carter
  2004-02-13  1:21 ` Stephen Leake
  4 siblings, 0 replies; 11+ messages in thread
From: Ludovic Brenta @ 2004-02-12 20:54 UTC (permalink / raw)


scallassig@mailexpire.com (Harald Korneliussen) writes:

> I have been trying to solve some programming excercises from
> www.topcoder.com in Ada, just to compare it to Java and the other
> popular languages.
> 
> One problem I keep running into is the lack of common, useful
> utilities in the libraries that come with Gnat & Ada. One thing is
> that I had to write my own tokenizer. That gave me the opporunity to
> emulate the String.split() method in newer versions of Java, OK*. But
> now I have to do an even simpler task, converting a string of digits
> to an integer, and as far as I can see there is no function for this
> in the standard libraries!?

Look at Integer'Value in the reference manual 3.5 (52).  Example:

N : Integer := Integer'Value ("42");

> I hear there is a new revision of Ada coming. I really, really hope
> they adress the lack of a standard library of utillity packages
> instead of adding new language features.

The small size of the Ada standard library has been much debated here.
This does not mean that there are no libraries at all; I encourage you
to look at http://www.adaworld.com, http://www.adaic.com,
http://www.adapower.com, and http://libre.act-europe.fr.  These sites
list several Ada libraries which you may find useful.

> * Anyone want it? :-)

If you write some useful utilities that you are willing to share, I
think it would be a good idea to add them to one of these libraries
and join in the development.  As for your tokenizer, is it very
different from OpenToken?

-- 
Ludovic Brenta.



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

* Re: Simple library functions
  2004-02-12 19:37 Simple library functions Harald Korneliussen
                   ` (2 preceding siblings ...)
  2004-02-12 20:54 ` Ludovic Brenta
@ 2004-02-13  0:52 ` Jeffrey Carter
  2004-02-13  7:18   ` Harald Korneliussen
  2004-02-13  1:21 ` Stephen Leake
  4 siblings, 1 reply; 11+ messages in thread
From: Jeffrey Carter @ 2004-02-13  0:52 UTC (permalink / raw)


Harald Korneliussen wrote:

> One problem I keep running into is the lack of common, useful
> utilities in the libraries that come with Gnat & Ada. One thing is
> that I had to write my own tokenizer. That gave me the opporunity to
> emulate the String.split() method in newer versions of Java, OK*. But
> now I have to do an even simpler task, converting a string of digits
> to an integer, and as far as I can see there is no function for this
> in the standard libraries!?

There's no function for that in the standard library because it's part 
of the language. Others have pointed out the 'Value attribute.

I have no idea what String.split does in Java, but I suspect it's 
similar to Ada.Strings.(Fixed | Bounded | Unbounded).Find_Token. If not, 
you could look at www.adapower.com or www.adahome.com for Open_Token.

-- 
Jeff Carter
"I spun around, and there I was, face to face with a
six-year-old kid. Well, I just threw my guns down and
walked away. Little bastard shot me in the ass."
Blazing Saddles
40




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

* Re: Simple library functions
  2004-02-12 19:37 Simple library functions Harald Korneliussen
                   ` (3 preceding siblings ...)
  2004-02-13  0:52 ` Jeffrey Carter
@ 2004-02-13  1:21 ` Stephen Leake
  4 siblings, 0 replies; 11+ messages in thread
From: Stephen Leake @ 2004-02-13  1:21 UTC (permalink / raw)
  To: comp.lang.ada

scallassig@mailexpire.com (Harald Korneliussen) writes:

> I have been trying to solve some programming excercises from
> www.topcoder.com in Ada, just to compare it to Java and the other
> popular languages.
> 
> One problem I keep running into is the lack of common, useful
> utilities in the libraries that come with Gnat & Ada. One thing is
> that I had to write my own tokenizer. That gave me the opporunity to
> emulate the String.split() method in newer versions of Java, OK*. 

Have you looked at Ada.Strings.Fixed.Find_Token?

For really advanced tokenizing, you want OpenToken
(http://www.telepath.com/~dennison/Ted/OpenToken/OpenToken.html). 

-- 
-- Stephe




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

* Re: Simple library functions
  2004-02-13  0:52 ` Jeffrey Carter
@ 2004-02-13  7:18   ` Harald Korneliussen
  2004-02-13 12:54     ` Harald Korneliussen
  2004-02-13 21:55     ` Pascal Obry
  0 siblings, 2 replies; 11+ messages in thread
From: Harald Korneliussen @ 2004-02-13  7:18 UTC (permalink / raw)


Jeffrey Carter <spam@spam.com> wrote in message news:<kdVWb.1821

> 
> There's no function for that in the standard library because it's part 
> of the language. Others have pointed out the 'Value attribute.

Oops, you're right of course. I found it right after I posted, in a
tutorial. I couln't find it in the RM however, but then again I looked
at strings and integers only, not attributes.
 
> I have no idea what String.split does in Java, but I suspect it's 
> similar to Ada.Strings.(Fixed | Bounded | Unbounded).Find_Token. If not, 
> you could look at www.adapower.com or www.adahome.com for Open_Token.

String.split works like this:

String s = "hi he ha ho"

String strings[] = s.split();

// strings[] is now {"hi", "he", "ha", "ho"}

In java it takes a regexp, with " \t\n" as default. My function takes
a set of characters (from Ada.Characters.Maps), with the set of
whitespace as default.

I'll be right back....



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

* Re: Simple library functions
  2004-02-13  7:18   ` Harald Korneliussen
@ 2004-02-13 12:54     ` Harald Korneliussen
  2004-02-13 21:36       ` Randy Brukardt
  2004-02-13 21:55     ` Pascal Obry
  1 sibling, 1 reply; 11+ messages in thread
From: Harald Korneliussen @ 2004-02-13 12:54 UTC (permalink / raw)


scallassig@mailexpire.com (Harald Korneliussen) wrote in message news:<19401efb.0402122318.68154453@posting.google.com>...
> Jeffrey Carter <spam@spam.com> wrote in message news:<kdVWb.1821
> 
> > 
> > There's no function for that in the standard library because it's part 
> > of the language. Others have pointed out the 'Value attribute.
> 
> Oops, you're right of course. I found it right after I posted, in a
> tutorial. I couln't find it in the RM however, but then again I looked
> at strings and integers only, not attributes.
>  
> > I have no idea what String.split does in Java, but I suspect it's 
> > similar to Ada.Strings.(Fixed | Bounded | Unbounded).Find_Token. If not, 
> > you could look at www.adapower.com or www.adahome.com for Open_Token.
> 
> String.split works like this:
> 
> String s = "hi he ha ho"
> 
> String strings[] = s.split();
> 
> // strings[] is now {"hi", "he", "ha", "ho"}
> 
> In java it takes a regexp, with " \t\n" as default. My function takes
> a set of characters (from Ada.Characters.Maps), with the set of
> whitespace as default.
> 
> I'll be right back....

Apropos that: when I looked at gnat's regexp package I saw a comment
about certain functions being evaluated twice, once to determine the
size and another time to actually produce the results. Have I
understood correctly that in for instance

s : String := function_returning_a_string_of_variable_length(junk :
Integer);

the function is actually evaluated twice? (Stupid question of me to
ask, really, but I don't have an Ada compiler at school). Would it do
that in java too?



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

* Re: Simple library functions
  2004-02-13 12:54     ` Harald Korneliussen
@ 2004-02-13 21:36       ` Randy Brukardt
  0 siblings, 0 replies; 11+ messages in thread
From: Randy Brukardt @ 2004-02-13 21:36 UTC (permalink / raw)


"Harald Korneliussen" <scallassig@mailexpire.com> wrote in message
news:19401efb.0402130454.2779b091@posting.google.com...
...
> Apropos that: when I looked at gnat's regexp package I saw a comment
> about certain functions being evaluated twice, once to determine the
> size and another time to actually produce the results. Have I
> understood correctly that in for instance
>
> s : String := function_returning_a_string_of_variable_length(junk :
> Integer);
>
> the function is actually evaluated twice?

No, the function is evaluated only once. The compiler has to return the
string and the bounds from the function at one time. Dunno what's going on
in GNAT's libraries.

                      Randy.






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

* Re: Simple library functions
  2004-02-13  7:18   ` Harald Korneliussen
  2004-02-13 12:54     ` Harald Korneliussen
@ 2004-02-13 21:55     ` Pascal Obry
  2004-02-14 16:14       ` Harald Korneliussen
  1 sibling, 1 reply; 11+ messages in thread
From: Pascal Obry @ 2004-02-13 21:55 UTC (permalink / raw)



scallassig@mailexpire.com (Harald Korneliussen) writes:

> String strings[] = s.split();
> 
> // strings[] is now {"hi", "he", "ha", "ho"}
> 
> In java it takes a regexp, with " \t\n" as default. My function takes
> a set of characters (from Ada.Characters.Maps), with the set of
> whitespace as default.

You can do that easily with my String_Cutter package. See my homepage in the
Ada -> Download section.

GNAT has now an equivalent package named GNAT.String_Split.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Simple library functions
  2004-02-13 21:55     ` Pascal Obry
@ 2004-02-14 16:14       ` Harald Korneliussen
  0 siblings, 0 replies; 11+ messages in thread
From: Harald Korneliussen @ 2004-02-14 16:14 UTC (permalink / raw)


> GNAT has now an equivalent package named GNAT.String_Split.
> 
> Pascal.

Wow, that's cool! But I've got gcc 3.3.3 with GNAT, and I can't find
it ... wait a minute! I've been using my old installation as a
reference! Duh! :-)



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

end of thread, other threads:[~2004-02-14 16:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-12 19:37 Simple library functions Harald Korneliussen
2004-02-12 19:50 ` Ed Falis
2004-02-12 19:54 ` Ed Falis
2004-02-12 20:54 ` Ludovic Brenta
2004-02-13  0:52 ` Jeffrey Carter
2004-02-13  7:18   ` Harald Korneliussen
2004-02-13 12:54     ` Harald Korneliussen
2004-02-13 21:36       ` Randy Brukardt
2004-02-13 21:55     ` Pascal Obry
2004-02-14 16:14       ` Harald Korneliussen
2004-02-13  1:21 ` Stephen Leake

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