* Question: dynamic rename?
@ 2011-09-03 2:28 Darkwing
2011-09-03 8:03 ` Dmitry A. Kazakov
2011-09-03 12:27 ` ytomino
0 siblings, 2 replies; 9+ messages in thread
From: Darkwing @ 2011-09-03 2:28 UTC (permalink / raw)
Is there an Ada elegant way to do something like the following:
signal : signal_type renames =>
case configuration is
when one => signal_one;
when two => signal_two;
end case;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Question: dynamic rename?
2011-09-03 2:28 Question: dynamic rename? Darkwing
@ 2011-09-03 8:03 ` Dmitry A. Kazakov
2011-09-03 10:04 ` Simon Wright
2011-09-03 12:27 ` ytomino
1 sibling, 1 reply; 9+ messages in thread
From: Dmitry A. Kazakov @ 2011-09-03 8:03 UTC (permalink / raw)
On Fri, 2 Sep 2011 19:28:38 -0700 (PDT), Darkwing wrote:
> Is there an Ada elegant way to do something like the following:
>
> signal : signal_type renames =>
> case configuration is
> when one => signal_one;
> when two => signal_two;
> end case;
Nested subprogram taking signal as an argument.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Question: dynamic rename?
2011-09-03 8:03 ` Dmitry A. Kazakov
@ 2011-09-03 10:04 ` Simon Wright
2011-09-03 10:47 ` Dmitry A. Kazakov
0 siblings, 1 reply; 9+ messages in thread
From: Simon Wright @ 2011-09-03 10:04 UTC (permalink / raw)
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> On Fri, 2 Sep 2011 19:28:38 -0700 (PDT), Darkwing wrote:
>
>> Is there an Ada elegant way to do something like the following:
>>
>> signal : signal_type renames =>
>> case configuration is
>> when one => signal_one;
>> when two => signal_two;
>> end case;
>
> Nested subprogram taking signal as an argument.
I thought that, but what if signal_one, signal_two were variables and
you needed an lvalue? I think you'd need to return an access value. Must
depend very much on context.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Question: dynamic rename?
2011-09-03 10:04 ` Simon Wright
@ 2011-09-03 10:47 ` Dmitry A. Kazakov
0 siblings, 0 replies; 9+ messages in thread
From: Dmitry A. Kazakov @ 2011-09-03 10:47 UTC (permalink / raw)
On Sat, 03 Sep 2011 11:04:05 +0100, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> On Fri, 2 Sep 2011 19:28:38 -0700 (PDT), Darkwing wrote:
>>
>>> Is there an Ada elegant way to do something like the following:
>>>
>>> signal : signal_type renames =>
>>> case configuration is
>>> when one => signal_one;
>>> when two => signal_two;
>>> end case;
>>
>> Nested subprogram taking signal as an argument.
>
> I thought that, but what if signal_one, signal_two were variables and
> you needed an lvalue?
declare
procedure Do_Things (Signal : in out Signal_Type) is
begin
...
end Do_Things;
begin
case Configuration is
when one =>
Do_Things (Signal_one);
when two =>
Do_Things (Signal_two);
end case;
...
?
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Question: dynamic rename?
2011-09-03 2:28 Question: dynamic rename? Darkwing
2011-09-03 8:03 ` Dmitry A. Kazakov
@ 2011-09-03 12:27 ` ytomino
2011-09-03 13:22 ` Pascal Obry
1 sibling, 1 reply; 9+ messages in thread
From: ytomino @ 2011-09-03 12:27 UTC (permalink / raw)
If signal_one and signal_two are (aliased) variable,
function signal_ref return access signal_type is
begin
case configuration is
when one => return signal_one'Access;
when two => return signal_two'Access;
end case;
end signal_ref;
signal : signal_type renames signal_ref.all;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Question: dynamic rename?
2011-09-03 12:27 ` ytomino
@ 2011-09-03 13:22 ` Pascal Obry
2011-09-04 3:11 ` Darkwing
0 siblings, 1 reply; 9+ messages in thread
From: Pascal Obry @ 2011-09-03 13:22 UTC (permalink / raw)
To: ytomino
Le 03/09/2011 14:27, ytomino a �crit :
> If signal_one and signal_two are (aliased) variable,
>
> function signal_ref return access signal_type is
> begin
> case configuration is
> when one => return signal_one'Access;
> when two => return signal_two'Access;
> end case;
> end signal_ref;
>
> signal : signal_type renames signal_ref.all;
Or using a case expression in Ada 2012:
Signal : Signal_Type :=
(case Configuration is
when One => Signal_One,
when Two => Signal_Two);
Pascal.
--
--|------------------------------------------------------
--| 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Question: dynamic rename?
2011-09-03 13:22 ` Pascal Obry
@ 2011-09-04 3:11 ` Darkwing
2011-09-04 8:43 ` Pascal Obry
0 siblings, 1 reply; 9+ messages in thread
From: Darkwing @ 2011-09-04 3:11 UTC (permalink / raw)
On Sep 3, 6:22 am, Pascal Obry <pas...@obry.net> wrote:
> Le 03/09/2011 14:27, ytomino a écrit :
>
>
> Or using a case expression in Ada 2012:
>
> Signal : Signal_Type :=
> (case Configuration is
> when One => Signal_One,
> when Two => Signal_Two);
You can really do that in Ada 2012? (I've never used 2012, just 95).
That's pretty cool. Any word on when 2012 will be finalized?
> function signal_ref return access signal_type is
> begin
> case configuration is
> when one => return signal_one'Access;
> when two => return signal_two'Access;
> end case;
> end signal_ref;
This is what I'll have to use. Well, actually just the value since I'm
only reading and not writing. Also, I don't think I have have access
to the 'access because the variables in question aren't aliased (I
don't believe they are aliasable either).
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Question: dynamic rename?
2011-09-04 3:11 ` Darkwing
@ 2011-09-04 8:43 ` Pascal Obry
2011-09-07 16:35 ` Anh Vo
0 siblings, 1 reply; 9+ messages in thread
From: Pascal Obry @ 2011-09-04 8:43 UTC (permalink / raw)
To: Darkwing
Le 04/09/2011 05:11, Darkwing a �crit :
> On Sep 3, 6:22 am, Pascal Obry<pas...@obry.net> wrote:
>> Or using a case expression in Ada 2012:
>>
>> Signal : Signal_Type :=
>> (case Configuration is
>> when One => Signal_One,
>> when Two => Signal_Two);
>
> You can really do that in Ada 2012? (I've never used 2012, just 95).
Yes, and this already works in GNAT recent versions. Not tested with
GNAT GPL 2011 though.
> That's pretty cool. Any word on when 2012 will be finalized?
ISO standardization should be completed in 2012. Implementation of some
features has already started in GNAT but for a full Ada 2012 support it
will take some time. More information about Ada 2012:
http://www.adacore.com/home/ada_answers/ada-2012/
http://www.ada-auth.org/standards/ada12.html
You probably want to read this introduction to Ada 2012:
http://www2.adacore.com/wp-content/uploads/2006/03/Ada2012_Rational_Introducion.pdf
Pascal.
--
--|------------------------------------------------------
--| 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Question: dynamic rename?
2011-09-04 8:43 ` Pascal Obry
@ 2011-09-07 16:35 ` Anh Vo
0 siblings, 0 replies; 9+ messages in thread
From: Anh Vo @ 2011-09-07 16:35 UTC (permalink / raw)
On Sep 4, 1:43 am, Pascal Obry <pas...@obry.net> wrote:
> Le 04/09/2011 05:11, Darkwing a écrit :
>
> > On Sep 3, 6:22 am, Pascal Obry<pas...@obry.net> wrote:
> >> Or using a case expression in Ada 2012:
>
> >> Signal : Signal_Type :=
> >> (case Configuration is
> >> when One => Signal_One,
> >> when Two => Signal_Two);
>
> > You can really do that in Ada 2012? (I've never used 2012, just 95).
>
> Yes, and this already works in GNAT recent versions. Not tested with
> GNAT GPL 2011 though.
It does work with GNAT GPL 2011 On Windows at least.
Anh Vo
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-09-07 16:35 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-03 2:28 Question: dynamic rename? Darkwing
2011-09-03 8:03 ` Dmitry A. Kazakov
2011-09-03 10:04 ` Simon Wright
2011-09-03 10:47 ` Dmitry A. Kazakov
2011-09-03 12:27 ` ytomino
2011-09-03 13:22 ` Pascal Obry
2011-09-04 3:11 ` Darkwing
2011-09-04 8:43 ` Pascal Obry
2011-09-07 16:35 ` Anh Vo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox