From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Renaming vs assignment to constant
Date: Fri, 6 Dec 2013 13:59:21 -0800 (PST)
Date: 2013-12-06T13:59:21-08:00 [thread overview]
Message-ID: <361fb7d4-d22e-4ac3-a307-48108c4f8eb0@googlegroups.com> (raw)
In-Reply-To: <lypppaj9jo.fsf@pushface.org>
On Friday, December 6, 2013 8:14:51 AM UTC-7, Simon Wright wrote:
> A poster on Stack Overflow wrote
>
> Now : Time renames Clock;
That was me! :)
> (using Ada.Calendar) which made me blink until I realised that it is the
> equivalent of
>
> Now : constant Time := Clock;
Yep, it is. I probably used it because I had recently run into a C# problem where renaming a variable [and typecast] would have been *VERY* useful.
'Renames' doesn't get enough love; its been neglected over the past [few] standard revisions. -- After using some of the Ada1012 features it'd be kinda nice to put pre/post conditions on a callback independent of those of the actual subprogram referenced; perhaps:
type callback_type is not null access procedure;
Procedure Some_Procedure;
--...
callback : callback_type renames procedure'access
with pre => [...], post => [...];
Generics are another feature that seems to have been neglected (for 2005 and 2012), even though they're really pretty good in Ada they could be better still... perhaps a bit of polishing such as allowing Instantiation.Input_variable on formal parameter Input_Variable (conceptually IN would map to constant, IN OUT to a variable, and OUT should likely be handled as an out parameter in a subprogram): this would allow for clients of an instantiation to depend on it w/o having to be generics themselves.
> GNAT generates the same code for these two forms. Is there a difference?
> Which form is preferred?
I think the big difference happens when the result has subcomponents:
ch : constant Character:= 'X'; -- Character X.
temp : String renames Character'Image(ch); -- Its image: 'X'.
ch2 : Character renames temp(2); -- The unquoted character.
next prev parent reply other threads:[~2013-12-06 21:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-06 15:14 Renaming vs assignment to constant Simon Wright
2013-12-06 16:09 ` Jeffrey Carter
2013-12-06 18:03 ` AdaMagica
2013-12-06 18:24 ` Jeffrey Carter
2013-12-06 16:47 ` adambeneschan
2013-12-06 18:06 ` Eryndlia Mavourneen
2013-12-07 0:47 ` Randy Brukardt
2013-12-07 1:55 ` Shark8
2013-12-06 18:35 ` G.B.
2013-12-06 20:07 ` adambeneschan
2013-12-06 21:59 ` Shark8 [this message]
2013-12-06 23:48 ` adambeneschan
2013-12-07 1:04 ` Shark8
2013-12-07 1:26 ` adambeneschan
2013-12-07 6:17 ` J-P. Rosen
2013-12-07 6:22 ` J-P. Rosen
2013-12-07 8:57 ` Dmitry A. Kazakov
2013-12-07 9:02 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox