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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d855403bbf39dab1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.189.72 with SMTP id gg8mr8788316pbc.4.1328440330590; Sun, 05 Feb 2012 03:12:10 -0800 (PST) Path: lh20ni262932pbb.0!nntp.google.com!news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!fdn.fr!feeder.news.orange.fr!not-for-mail Date: Sun, 05 Feb 2012 12:12:09 +0100 From: Pascal Obry Organization: Home - http://www.obry.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; fr-FR; rv:1.8.1.22) Gecko/20090605 Thunderbird/2.0.0.22 Mnenhy/0.7.5.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: can one create an array of a size determined by a constant value of a function? References: In-Reply-To: Message-ID: <4f2e6409$0$21490$ba4acef3@reader.news.orange.fr> NNTP-Posting-Date: 05 Feb 2012 12:12:09 CET NNTP-Posting-Host: 86.195.51.17 X-Trace: 1328440329 reader.news.orange.fr 21490 86.195.51.17:11562 X-Complaints-To: abuse@orange.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Date: 2012-02-05T12:12:09+01:00 List-Id: Le 04/02/2012 12:00, Nasser M. Abbasi a �crit : > Is it possible to do something like this in Ada? Yes, easier and better and since 1983 :) subtype Size is Positive range 1 .. 1_024; function Spaces (N : in Size) return String; -- Returns a string with N spaces function Spaces (N : in Size) return String is V : String (1 .. N) := (others => ' '); begin return V; end Spaces; N is not known at compile time and Spaces can be called by any other part of the application with any value of N. Note that in the above routine I have declared V to make it clear that an array with a variable length can be declared, but we can simplify this by writing: function Spaces (N : in Size) return String is begin return String'(1 .. N => ' '); end Spaces; Pascal. PS: all this code has not been compiled! -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net - http://v2p.fr.eu.org --| "The best way to travel is by means of imagination" --| --| gpg --keyserver keys.gnupg.net --recv-key F949BD3B