From: Pascal Obry <pascal@obry.net>
Subject: Re: can one create an array of a size determined by a constant value of a function?
Date: Sun, 05 Feb 2012 12:12:09 +0100
Date: 2012-02-05T12:12:09+01:00 [thread overview]
Message-ID: <4f2e6409$0$21490$ba4acef3@reader.news.orange.fr> (raw)
In-Reply-To: <jgj33s$290$1@speranza.aioe.org>
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
prev parent reply other threads:[~2012-02-05 11:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-04 11:00 can one create an array of a size determined by a constant value of a function? Nasser M. Abbasi
2012-02-04 12:03 ` Yannick Duchêne (Hibou57)
2012-02-04 18:36 ` Robert A Duff
2012-02-04 18:47 ` Jeffrey Carter
2012-02-05 11:12 ` Pascal Obry [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox