From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Ada 2012: In-out parameters for functions
Date: Wed, 1 May 2013 10:27:57 -0700 (PDT)
Date: 2013-05-01T10:27:57-07:00 [thread overview]
Message-ID: <c71ab530-d44f-41bd-ba4c-8b7fdcddec09@googlegroups.com> (raw)
In-Reply-To: <7704abab-86f2-4edc-ad4b-b3d4e70004fb@googlegroups.com>
On Wednesday, May 1, 2013 10:28:07 AM UTC-6, dpt...@arcor.de wrote:
>
> So, when do I use functions or procedures. Functions have return values. Any other differences?
Not really. Though a function w/ out parameters could be used like this:
-- Given Recognize(P : Pattern, S : String, O : out Object_Type) Return Boolean
if Recognize( Pattern_1, Input, Object ) then
-- process object
elsif Recognize( Pattern_2, Input, Object ) then
-- process object
end if;
Another thing is that functions can output unconstrained types [but the result is constrained], which means they can be used to assign to arrays or tagged-type 'CLASSes or the or discriminated types.
So we could now have a tokenizer like this:
-- Token_List: Vector containing the type Token.
Function Tokenize(Input : String) Return Token_List is
-- Nested Tokenize consumes a portion of the string and returns a token.
Function Tokenize(Input : in out Unbounded_String) Return Token
with pre => Length(Unbounded_String) > 0;
[...]
Working : Unbounded_String:= To_Unbounded_String( Input );
begin
Return Result : Token_List do
while Length(Working) > 0 loop
Result.Append( Tokenize(Working) );
end loop;
End return;
end Tokenize;
next prev parent reply other threads:[~2013-05-01 17:27 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-01 16:28 Ada 2012: In-out parameters for functions dptrash
2013-05-01 17:27 ` Shark8 [this message]
2013-05-01 19:04 ` Yannick Duchêne (Hibou57)
2013-05-01 19:37 ` Dmitry A. Kazakov
2013-05-01 19:58 ` Yannick Duchêne (Hibou57)
2013-05-02 6:41 ` Dmitry A. Kazakov
2013-05-02 7:11 ` Yannick Duchêne (Hibou57)
2013-05-01 23:37 ` Peter C. Chapin
2013-05-03 10:48 ` anon
2013-05-03 11:04 ` Simon Clubley
2013-05-03 11:32 ` Simon Wright
2013-05-03 11:42 ` Yannick Duchêne (Hibou57)
2013-05-03 11:54 ` Yannick Duchêne (Hibou57)
2013-05-03 23:29 ` Randy Brukardt
2013-05-04 1:02 ` Adam Beneschan
2013-05-05 5:16 ` Randy Brukardt
2013-05-05 10:24 ` Niklas Holsti
2013-05-05 11:11 ` Yannick Duchêne (Hibou57)
2013-05-05 12:52 ` Bill Findlay
2013-05-05 15:09 ` Niklas Holsti
2013-05-05 19:23 ` Yannick Duchêne (Hibou57)
2013-05-05 20:37 ` Niklas Holsti
2013-05-07 0:30 ` Randy Brukardt
2013-05-07 2:36 ` Yannick Duchêne (Hibou57)
2013-05-05 19:45 ` Yannick Duchêne (Hibou57)
2013-05-06 15:40 ` Adam Beneschan
2013-05-06 16:17 ` Bill Findlay
2013-05-06 16:47 ` Adam Beneschan
2013-05-06 18:43 ` Bill Findlay
2013-05-07 0:07 ` Dennis Lee Bieber
2013-05-07 2:34 ` Yannick Duchêne (Hibou57)
2013-05-07 0:26 ` Randy Brukardt
2013-05-06 15:26 ` Adam Beneschan
2013-05-07 0:36 ` Randy Brukardt
2013-05-07 3:59 ` Yannick Duchêne (Hibou57)
2013-05-07 4:13 ` Yannick Duchêne (Hibou57)
2013-05-07 11:52 ` Yannick Duchêne (Hibou57)
2013-05-03 11:45 ` AdaMagica
2013-05-03 23:54 ` Randy Brukardt
2013-05-04 6:58 ` J-P. Rosen
2013-05-04 7:21 ` Dmitry A. Kazakov
2013-05-04 17:58 ` J-P. Rosen
2013-05-04 7:40 ` Yannick Duchêne (Hibou57)
2013-05-04 8:05 ` Simon Wright
2013-05-04 17:55 ` J-P. Rosen
2013-05-04 0:40 ` Keith Thompson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox