From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9fa5063fbdc75ae4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-16 14:47:31 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Marius Amado Alves Newsgroups: comp.lang.ada Subject: Re: array of strings in a function Date: Thu, 16 Oct 2003 21:44:16 +0000 Organization: Cuivre, Argent, Or Message-ID: References: <8unsov8a3r9p02lm0ftkmmget77esc7fv7@4ax.com> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1066340700 81254 80.67.180.195 (16 Oct 2003 21:45:00 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Thu, 16 Oct 2003 21:45:00 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: X-Mailer: Ximian Evolution 1.4.5 X-OriginalArrivalTime: 16 Oct 2003 21:38:14.0271 (UTC) FILETIME=[CDBDC0F0:01C3942D] X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:1022 Date: 2003-10-16T21:44:16+00:00 Craig Carey wrote: "Some of the other solutions seem worse." Your array solution is probably the most "Adaist". But I liked Robert Eachus's. I wrote a variant which allows a list of size 1 (something Robert's doesn't), e.g. Show (+ "one"); Show (+ "one" + "two"); Show (+ "one" + "two" + "three"); Full source below. Vararg_Test outputs, as expected: 1=>one 1=>one 2=>two 1=>one 2=>two 3=>three (Too much free time in our hands uh? :-) with Vararg; use Vararg; with Ada.Text_IO; procedure Vararg_Test is L : List; procedure Show (L : List) is use Ada.Text_IO; begin for I in 1 .. Length (L) loop Put_Line (Integer'Image (I) & "=>" & Get (L, I)); end loop; New_Line; end; begin Show (+ "one"); Show (+ "one" + "two"); Show (+ "one" + "two" + "three"); end; with Ada.Strings.Unbounded; package Vararg is type List is private; function Length (L : List) return Natural; function Get (L : List; I : Positive) return String; function "+" (R : String) return List; function "+" (L : List; R : String) return List; private type Store is array (1 ..1000) of Ada.Strings.Unbounded.Unbounded_String; type List is record S : Store; N : Natural range 0 .. Store'Last := 0; end record; end; package body Vararg is function Length (L : List) return Natural is begin return L.N; end; use Ada.Strings.Unbounded; function Get (L : List; I : Positive) return String is begin return To_String (L.S (I)); end; function "+" (R : String) return List is Y : List; begin Y.S (1) := To_Unbounded_String (R); Y.N := 1; return Y; end; function "+" (L : List; R : String) return List is Y : List; begin Y.S (1 .. Length (L)) := L.S (1 .. Length (L)); Y.S (Length (L) + 1) := To_Unbounded_String (R); Y.N := Length (L) + 1; return Y; end; end;