From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Comments requested for a couple of Ada-Comments submissions
Date: Fri, 11 Jul 2014 19:04:31 +0300
Date: 2014-07-11T19:04:31+03:00 [thread overview]
Message-ID: <c2ag8cFi21iU1@mid.individual.net> (raw)
In-Reply-To: <lpnoet$hpu$1@loke.gir.dk>
On 14-07-11 07:16 , Randy Brukardt wrote:
> "Jeffrey Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message
> news:lpnb74$kmi$1@dont-email.me...
> ...
>> I don't see that there is anything here that the ARG would want to take
>> action on, especially given that Randy said they're only interested in
>> things that are hard or impossible to do in Ada. This is clearly not hard
>> or impossible.
>
> Well, actually, I understand that a similar problem came up recently (I
> think it was related to SPARK) and that the GNAT people had already hacked
> an ugly solution to it. A language-based solution would be better, at least
> if it's not too expensive to implement.
>
> After all, two independent problems that can be solved with a relatively
> simple new feature make that feature more compelling. In any case, it's
> certainly OK for Simon to submit the problem; I've seen a lot sillier ideas
> than this one.
>
> Randy.
Thanks, Simon, for working up this proposal.
I think that this proposal should not be limited to solving the "update
of atomic" problem. The ability to write an aggregate that generates a
composite value by giving new values for just some of the components of
an existing composite value is quite useful in any context where a
composite value is used.
Such expressions are a mainstay of functional programming, which I feel
that Ada should support as a programming style, even if Ada is not a
pure functional language.
For example, given a record type Rec with many components, one of which
is Colour, a variable R of type Rec, and the need to call procedure Foo
twice, once using R with its own Colour, and once with R but using the
Black colour, we could do:
Foo (R);
Foo ((R changing Colour => Black));
There are two ways to do this in current Ada, but both are ugly. The
first uses a temporary variable, a copy, and an assignment to the component:
declare
T : Rec := R;
begin
Foo (R);
T.Colour := Black;
Foo (T);
end;
The other way uses an aggregate listing all components of Rec, which is
very cumbersome and a burden for maintenance:
Foo (R);
Foo ((X => R.X, Y => R.Y, ...., Colour => Black));
Furthermore, the proposal should IMO not be limited to record types. The
same should be possible for array aggregates, as in this example:
type Month_Days is array (Month) of Positive;
Normal_Year_Days : constant Month_Days :=
(Jan => 31, Feb => 28, Mar => 31, ..., Dec => 31);
Leap_Year_Days : constant Month_Days :=
(Normal_Year_Days changing Feb => 29);
As for the choice of keyword, while I agree that the best reading flow
needs a new keyword, I think that some existing keywords would be
tolerable, for example "overriding" as already suggested. Or how about
"new":
(R new Colour => Black)
(Normal_Year_Days new Feb => 28)
If we want a new keyword, I would suggest something short and almost
meaningless in itself, and therefore less likely to be used as an
identifier. For example "but":
(R but Colour => Black)
(Normal_Year_Days but Feb => 28)
Of course, there may be some French Ada programs using "But" as an
identifier, meaning "goal".
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
next prev parent reply other threads:[~2014-07-11 16:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-11 0:02 Comments requested for a couple of Ada-Comments submissions Simon Clubley
2014-07-11 0:30 ` Jeffrey Carter
2014-07-11 4:16 ` Randy Brukardt
2014-07-11 16:04 ` Niklas Holsti [this message]
2014-07-11 16:24 ` Dan'l Miller
2014-07-11 20:02 ` Simon Clubley
2014-07-12 5:52 ` Niklas Holsti
2014-07-11 4:26 ` Randy Brukardt
2014-07-11 7:05 ` Simon Clubley
2014-07-11 4:56 ` Shark8
2014-07-11 15:35 ` Adam Beneschan
2014-07-11 17:26 ` Niklas Holsti
2014-07-11 17:55 ` Adam Beneschan
2014-07-11 18:00 ` Simon Wright
2014-07-11 19:07 ` Georg Bauhaus
2014-07-11 19:10 ` Dmitry A. Kazakov
2014-07-11 19:16 ` Niklas Holsti
2014-07-11 19:35 ` Dmitry A. Kazakov
2014-07-11 21:24 ` Randy Brukardt
2014-07-11 21:46 ` Shark8
2014-07-11 19:30 ` Simon Clubley
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox