comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeff C," <nolongersafeto@userealemailsniff.com>
Subject: Re: array of strings in a function
Date: Wed, 15 Oct 2003 03:29:39 GMT
Date: 2003-10-15T03:29:39+00:00	[thread overview]
Message-ID: <Da3jb.779643$uu5.136255@sccrnsc04> (raw)
In-Reply-To: 3F8CB712.2070808@comcast.net

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2081 bytes --]


"Robert I. Eachus" <rieachus@comcast.net> wrote in message
news:3F8CB712.2070808@comcast.net...
> Antonio Mart�nez wrote:
>
> > I'm trying to pass to a function an argument. The argument is an
> > array range <> of Strings (unbounded array).
>
> > number of string literals is unknown by the function. And the
> > length of every string is unknown as well.
>
> > How do I work with unbound strings?
>
> You can create an array of Unbounded_String (found in
> Ada.Strings.Unbounded).  Or you can use the package below.  Note that in
> either case, you are going to have to create an array object, put the
> strings in it, and then pass that to the array.  With the package below
> your example above:
>

Hmm.. Robert, I am not sure why you would have to create the array and then
put the strings in it then pass
the array (ok, I agree that is what is really going to happen...but you can
hide it)

with Ada.Strings.Unbounded;
with Text_IO;

procedure AnotherWay is

  function "-"(Item : in String) return
Ada.Strings.Unbounded.Unbounded_String renames
Ada.Strings.Unbounded.To_Unbounded_String;
  function "-"(Item : in Ada.Strings.Unbounded.Unbounded_String) return
String renames Ada.Strings.Unbounded.To_String;

  type Unbounded_String_Array is array (Integer range <>) of
Ada.Strings.Unbounded.Unbounded_String;

  procedure Something (Data : in Unbounded_String_Array) is

  begin
    for I in Data'range loop
      Text_IO.Put_Line(-Data(I));
    end loop;
  end Something;

begin

  Something((-"Hello", -", I'm", -" the function"));

end AnotherWay;


Now, having said and done this....I agree with Robert that this is not a
normal Ada idiom
so the original poster should really think about whether or not you want to
do this.
While the code I provided above will actually work, it is really a bad idea
so if
you can look at your problem space in a different manner, I would really
recommend
against doing this.


Also one more note, the original post talked about writing a function to do
something but the example
(in the original post) was actually a procedure.





  reply	other threads:[~2003-10-15  3:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-14 20:54 array of strings in a function Antonio Martínez
2003-10-15  2:55 ` Robert I. Eachus
2003-10-15  3:29   ` Jeff C, [this message]
2003-10-15  3:08 ` Jeffrey Carter
2003-10-16  6:40   ` tmoran
2003-10-16  9:31     ` Craig Carey
2003-10-16 18:13       ` Craig Carey
2003-10-16 21:44         ` Marius Amado Alves
2003-10-17 19:48           ` Craig Carey
2003-10-18 10:05             ` Marius Amado Alves
2003-10-18 20:05               ` Craig Carey
2003-10-30  9:42                 ` Craig Carey
2003-10-16 17:58     ` Jeffrey Carter
2003-10-16 20:00       ` tmoran
2003-10-17  0:51         ` Jeffrey Carter
2003-10-15 11:49 ` Antonio Martínez Álvarez
2003-10-15 12:29   ` Preben Randhol
2003-10-15 14:19   ` Ole-Hjalmar Kristensen
2003-10-16 14:30   ` Robert I. Eachus
2003-10-16 17:53     ` Jeffrey Carter
2003-10-17  0:48       ` Robert I. Eachus
2003-10-17 18:41         ` Jeffrey Carter
replies disabled

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