comp.lang.ada
 help / color / mirror / Atom feed
* conversion
@ 1998-07-22  0:00 Rick
  1998-07-22  0:00 ` conversion Corey Ashford
  1998-07-22  0:00 ` conversion Richard Toy
  0 siblings, 2 replies; 44+ messages in thread
From: Rick @ 1998-07-22  0:00 UTC (permalink / raw)


how do you convert a string into an integer?
thanks





^ permalink raw reply	[flat|nested] 44+ messages in thread
* conversion
@ 2003-06-27 10:51 Andrew
  2003-06-27 12:22 ` conversion Dmitry A. Kazakov
                   ` (5 more replies)
  0 siblings, 6 replies; 44+ messages in thread
From: Andrew @ 2003-06-27 10:51 UTC (permalink / raw)
  To: comp.lang.ada

I am experimenting with Ada as the primary language in our process.  It
seems that
the use of String and Unbounded_String require converting from one to the
other in
order to read a line from a file and then trim it or slice it or tokenize
it.  For now,
regardless of the performance of these conversions it is rather inconvenient
to design
for a language that does not have a "universal" string type.

For instance:  a variable of type char * can be used as char * or as char []
and char []
can be used as char *.  A fixed string in Ada (to me) is like declaring a
char [], you
must specify a size at compile time.  An unbounded_string in Ada is like
char *, it can
take on a different size when it appears on the LHS of an assignment
operator.  The
catch is that unbounded_string can not be used in context of string.  This
posses some
design inconveniences and requires converting back and forth from string to
unbounded_string multiple times.

I defined a string pointer type so that I could dynamically create strings
that are the fixed
string type but I find that 'that' only defers the need to convert from
fixed string to
unbounded_string to different points in the design or that the conversion is
not eliminated.
I am now thinking that for my company we could develop a "library" that has
a "universal"
string type.  If we don't base it on the defined string in package standard
and can use
streams to read from files then we can define our own string type.  I
think...

I'm not real sure whether to extend on the functionality of ada.text_io or
to create new
functionality from the stream package.  Any recommendations?  Has anyone
done
something like this?

Andrew





^ permalink raw reply	[flat|nested] 44+ messages in thread
* conversion
@ 2003-06-27 17:37 Andrew
  2003-06-27 17:32 ` conversion Stephen Leake
  2003-06-28  2:55 ` conversion Jeffrey Carter
  0 siblings, 2 replies; 44+ messages in thread
From: Andrew @ 2003-06-27 17:37 UTC (permalink / raw)
  To: comp.lang.ada

Ok, so I found the ada.strings.unbounded package spec and body and took a
look
at the definition and implementation of unbounded string.  Finally I found
them!

Unbounded_string is basically an object that contains a reference to a
string.
It would be something like:

typdef struct unbounded_string{
    char* reference;
}

with methods to manipulate the structure.  My example may not be
syntactically correct
but I think I convey the basic idea.  String is an array, Unbounded_String
is an
"object" that contains a reference to an array.

So...The conversion from Unbounded_String to String is pretty easy.  Return
the
pointer de-reference.  From String to Unbounded_String is the expensive one.
In
general it is:
allocate memory
copy values from old to new
return the new.

So, using unbounded and calling to_string is relatively fast.  Good, I'm
satisfied with
that part.  I think it would be easy enough to create a slice and trim
method that
returned an unbounded_string so that I would not have to use the expensive
string to
unbounded_string conversion and that nagging inconvenience would be
pacified.

Dmitry mentioned that get_line reads in to a string buffer.  Then after the
line
was read another string could be made because the last parameter is the
length of
what was read.  Your absolutely right!  I knew that and looked right over
it.

It wasn't hard at all to write a program that uses to_string and
to_unbounded_string.
It works.  It's just that I didn't realize in design that I would need so
many conversions
and I wasn't fluent enough with all the "utility" methods like slice, trim,
head, etcetera
to really specify at design time whether I needed String or
Unbounded_String.  Once
implementation time came up I almost immediately had to go back to design
because
I was introducing so much code for the conversions.  I thought "there has to
be a better
way".

Something else I really like about Ada is separate compilation.  I can
separate subprocedures
into other files with the "is separate" and Separate(<name>) feature.  That
one thing would
make code SO much more manageable.  I could spread that thing out and assign
tasks by
function if needed.  Then, just compile!

I also was trying to get gnatmem to run but it fails.

Has anyone used the Ada Core Technologies compiler?  How does it compare to
the public
GNAT that I'm using; comes with FreeBSD Unix.

Thanks for the help!

Andrew









^ permalink raw reply	[flat|nested] 44+ messages in thread
* conversion
@ 2003-06-28  8:46 Andrew
  2003-06-28  9:49 ` conversion Preben Randhol
  2003-06-30 14:08 ` conversion Stephen Leake
  0 siblings, 2 replies; 44+ messages in thread
From: Andrew @ 2003-06-28  8:46 UTC (permalink / raw)
  To: comp.lang.ada

The more I think about the string/unbounded_string inconvenience the
more I think about polymorphism.  Polymorphism helps readability in
some situations.  In the case of the 'utilities' functions I think
polymorphism
would provide a great service.

The "flavor" that char* and char[] as parameters in functions is that they
seem interchangeable.  I can pass a char* into a function declared to use
char[], and vice-versa.  It's not that way in Ada, most likely for a real
good
reason, but it would sure be nice if there were a way to make it seem that
easy in Ada.

Enter polymorphism.

If overloaded slice inside Unbounded package to return an unbounded_string
an unbounded_string would still need to be created.  I don't think there is
any
way around that part but having the overloaded slice function would bring a
type transparent feeling to using the slice function and many others as
well.
Polymorphism in this case would help.  One way to achieve polymorphism is to
overload the 'utility' functions.

That explains why I had the feeling of extending the functionality of the
Unbounded
package.  It doesn't seem complete.

-- In regard to separate compilation
>Better to use child packages. "is separate" is really an Ada 83
>feature; child packages in Ada 95 is a better way to structure things.
>Sometimes "is separate" is a good way to go, but rarely.
Is the "is separate" feature going away?

-- In regard to gnatmem
gnatmem says it will start a program and you can provide the
command line arguments to it.
"gnatmem <program> <arg1> <arg2>..."

So, I have a program fashionably called testprog that takes two
command line arguments; a path and a filename.  So I try to run
gnatmem (after compiling with debug flag) like:

"gnatmem testprog . testdata.txt"

Gnatmem then says that the program ended unexpectedly.  I can
run "testprog . testdata.txt" from the command line and it works
fine.

-- In regard to GNAT
>Hmm, this is confused. GNAT _is_ the Ada Core Technologies (ACT)
>compiler.
Ok, how about the IDE portion?

Thanks for the help all!

Andrew




^ permalink raw reply	[flat|nested] 44+ messages in thread
* conversion
@ 2003-06-29  9:41 Andrew
  2003-07-04 10:42 ` conversion Janeit
  0 siblings, 1 reply; 44+ messages in thread
From: Andrew @ 2003-06-29  9:41 UTC (permalink / raw)
  To: comp.lang.ada

Just out of curiosity; what would be wrong with moving string into it's own
package?

Andrew




^ permalink raw reply	[flat|nested] 44+ messages in thread
[parent not found: <002701c33e22$8e9deaf0$0201a8c0@win>]

end of thread, other threads:[~2003-07-11  1:56 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-07-22  0:00 conversion Rick
1998-07-22  0:00 ` conversion Corey Ashford
1998-07-22  0:00   ` conversion Corey Ashford
1998-07-22  0:00 ` conversion Richard Toy
  -- strict thread matches above, loose matches on Subject: below --
2003-06-27 10:51 conversion Andrew
2003-06-27 12:22 ` conversion Dmitry A. Kazakov
2003-06-27 12:37 ` conversion Stephen Leake
2003-06-27 14:26   ` conversion Bill Findlay
2003-06-27 17:04     ` conversion Georg Bauhaus
2003-07-04  0:21     ` conversion Dave Thompson
2003-06-27 13:25 ` conversion Robert I. Eachus
2003-06-27 18:42   ` conversion tmoran
2003-06-27 14:49 ` conversion Matthew Heaney
2003-06-27 17:10 ` conversion Georg Bauhaus
2003-06-27 17:13 ` conversion Alexander Kopilovitch
2003-06-27 17:34   ` conversion Preben Randhol
2003-06-27 22:10     ` conversion Alexander Kopilovitch
2003-06-28  9:46       ` conversion Preben Randhol
2003-06-27 22:13   ` conversion Robert I. Eachus
2003-06-30  8:52     ` conversion Dmitry A. Kazakov
2003-07-03  7:03       ` conversion Robert I. Eachus
2003-07-09  7:42         ` conversion Dmitry A. Kazakov
2003-07-09 17:04           ` conversion Robert I. Eachus
2003-07-10 10:19             ` conversion Dmitry A. Kazakov
2003-07-11  1:56               ` conversion Alexander Kopilovitch
2003-07-05  2:40     ` conversion Alexander Kopilovitch
2003-07-05  6:33       ` conversion Georg Bauhaus
2003-07-05 17:06         ` conversion Alexander Kopilovitch
2003-07-06  3:53           ` conversion Robert I. Eachus
2003-07-06  5:13             ` conversion Jeffrey Carter
2003-07-06 12:45               ` conversion Chad R. Meiners
2003-07-07  1:09             ` conversion Alexander Kopilovitch
2003-07-06 20:04           ` conversion Georg Bauhaus
2003-07-07 14:55             ` conversion Stephen Leake
2003-07-07 21:36               ` conversion Alexander Kopilovitch
2003-06-27 17:37 conversion Andrew
2003-06-27 17:32 ` conversion Stephen Leake
2003-06-28  2:55 ` conversion Jeffrey Carter
2003-06-28  8:46 conversion Andrew
2003-06-28  9:49 ` conversion Preben Randhol
2003-06-30 14:08 ` conversion Stephen Leake
2003-06-29  9:41 conversion Andrew
2003-07-04 10:42 ` conversion Janeit
     [not found] <002701c33e22$8e9deaf0$0201a8c0@win>
2003-06-29 20:15 ` conversion David C. Hoos, Sr.

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