View Single Post
  #5 (permalink)  
Old 11-29-2007, 09:51 PM
Paul Uiterlinden
Guest
 
Posts: n/a
Default Re: return a variable size string

Jonathan Bromley wrote:

> One trick for getting around this is to move variable L
> outside your function, and then wrap the whole thing in
> yet another function. Like this (in which the "to_string"
> function merely makes a string of N asterisks, but you'll
> get the idea):
>
> impure function to_string(n: positive) return string is
> variable L: line;
> impure function to_string_inner(n: positive) return string is
> begin
> for i in 1 to n loop
> write(L, character' ('*') );
> end loop;
> return L.all;
> end;
> constant s: string := to_string_inner(n);
> begin
> deallocate(L);
> return s;
> end;
>
> Someone else may have some nicer ideas...


They don't come nicer than that one.
Elegant and simple.
I like it!

--
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.
Reply With Quote