Hello,
I'm puzzled when I want to changed a function body with aspects to an expression function, for instance:
function Length (S : Some_Tagged_Tyoe) return Natural
 with Pre => S.Valid
 is
 begin
 return S.Length;
 end;
have to be changed in:
function Length (S : Some_Tagged_Tyoe) return Natural
 is (S.Length)
 with Pre => S.Valid;
The location of the aspect has moved to the end.
I'd like simply replace the begin block by the expression, as:
function Length (S : Some_Tagged_Tyoe) return Natural
 with Pre => S.Valid
 is (S.Length);
What could be any reasons not to permit it?
Le 14/05/2022 à 13:47, Blady a écrit :
Hello,
I'm puzzled when I want to changed a function body with aspects to an
expression function, for instance:
function Length (S : Some_Tagged_Tyoe) return Natural
with Pre => S.Valid
is
begin
return S.Length;
end;
have to be changed in:
function Length (S : Some_Tagged_Tyoe) return Natural
is (S.Length)
with Pre => S.Valid;
The location of the aspect has moved to the end.
I'd like simply replace the begin block by the expression, as:
function Length (S : Some_Tagged_Tyoe) return Natural
with Pre => S.Valid
is (S.Length);
What could be any reasons not to permit it?
What you say is logical if you think of an expression function as a body; however, it is more like a specification (it can appear in a package spec, although it can complete a specification), so the place where the aspect appears makes sense. And it would be confusing to allow the aspect in two different places. It is the same for separate bodies of subprograms.
To make a functioning :LR grammar for Ada, I*had* to allow the aspect specification in both places, and then make one of them illegal. Which is more work than just allowing in either place. So I guess it is a matter of perspective.:-)
To the OP: we discussed placement of aspect specifications ad-nausem, as issues like this always were coming up. There is no consistent rule that really works well, because one does not want small things following large sets of aspect specs -- they can get lost and overlooked.
For instance, one puts aspect specifications after "is abstract" as
otherwise that could be lost after a lengthy precondition expression (and it's too important to be lost).
See how that could happen in the following
(illegal) declaration:
procedure P (A, B ,,,)
with Pre => <very long expression that extends over several lines here>
is abstract;
On 24.05.22 06:05, Randy Brukardt wrote:...
Who cares to see "is abstract" if P is in a spec?
The implementer, I guess, but the client? Less so.
Le 24/05/2022 à 06:05, Randy Brukardt a écrit :
To make a functioning :LR grammar for Ada, I*had* to allow the aspect
specification in both places, and then make one of them illegal. Which is
more work than just allowing in either place. So I guess it is a matter
of
perspective.:-)
But if you allow it in either place, then you have to decide what happens
if it appears in /both/ places... Would you like conformance checking? I
bet no ;-)
"G.B." <bauhaus@notmyhomepage.invalid> wrote in message news:t6j7se$8b1$1@dont-email.me...
On 24.05.22 06:05, Randy Brukardt wrote:...
Who cares to see "is abstract" if P is in a spec?
The implementer, I guess, but the client? Less so.
Any client that needs to declare an extension (pretty common in OOP),
especially as "abstract" routines mostly are used with root types (and interfaces). I suppose you could "program by error"
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 42:02:46 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,792 |