* Aspect location in expression function.
@ 2022-05-14 11:47 Blady
2022-05-14 15:40 ` J-P. Rosen
0 siblings, 1 reply; 8+ messages in thread
From: Blady @ 2022-05-14 11:47 UTC (permalink / raw)
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?
Thanks, Pascal.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Aspect location in expression function.
2022-05-14 11:47 Aspect location in expression function Blady
@ 2022-05-14 15:40 ` J-P. Rosen
2022-05-24 4:05 ` Randy Brukardt
0 siblings, 1 reply; 8+ messages in thread
From: J-P. Rosen @ 2022-05-14 15:40 UTC (permalink / raw)
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.
--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52
https://www.adalog.fr
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Aspect location in expression function.
2022-05-14 15:40 ` J-P. Rosen
@ 2022-05-24 4:05 ` Randy Brukardt
2022-05-24 10:01 ` J-P. Rosen
2022-05-24 18:24 ` G.B.
0 siblings, 2 replies; 8+ messages in thread
From: Randy Brukardt @ 2022-05-24 4:05 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3333 bytes --]
"J-P. Rosen" <rosen@adalog.fr> wrote in message
news:t5oigj$pag$1@dont-email.me...
> 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;
So something like this (and "is null" as well) require the Pre at the end:
procedure P (A, B ,,,)
is abstract
with Pre => <very long expression that extends over several lines
here>;
Expression functions generally follow the same rules as the older null
procedures, thus they ended up with the same positioning. It's not as
obvious a case here, since the return expression can also be long, but we
thought it should be consistent.
BTW, I don't think there ever is a reason to go from an expression with a
normal body to an expression function (assuming the body is legal). A normal
body is more readable and less of a hassle during maintenance. The advantage
of an expression function is to use it in places where a regular body is not
allowed and/or just to be lazy writing the body - neither of which would
ever require changing *to* an expression function. Maintenance might require
changing *from* an expression function if the body has gotten too complex
(for instance, needs a variable declaration), but that generally will
require moving the function as well so "ease" of doing so isn't very
relevant.
Randy.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Aspect location in expression function.
2022-05-24 4:05 ` Randy Brukardt
@ 2022-05-24 10:01 ` J-P. Rosen
2022-05-25 5:17 ` Randy Brukardt
2022-05-24 18:24 ` G.B.
1 sibling, 1 reply; 8+ messages in thread
From: J-P. Rosen @ 2022-05-24 10:01 UTC (permalink / raw)
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 ;-)
--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52
https://www.adalog.fr
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Aspect location in expression function.
2022-05-24 4:05 ` Randy Brukardt
2022-05-24 10:01 ` J-P. Rosen
@ 2022-05-24 18:24 ` G.B.
2022-05-25 5:20 ` Randy Brukardt
1 sibling, 1 reply; 8+ messages in thread
From: G.B. @ 2022-05-24 18:24 UTC (permalink / raw)
On 24.05.22 06:05, Randy Brukardt wrote:
> 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).
Isn't this emphasis on "is abstract" loosing the very point of abstraction?
> 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;
Who cares to see "is abstract" if P is in a spec?
The implementer, I guess, but the client? Less so.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Aspect location in expression function.
2022-05-24 10:01 ` J-P. Rosen
@ 2022-05-25 5:17 ` Randy Brukardt
0 siblings, 0 replies; 8+ messages in thread
From: Randy Brukardt @ 2022-05-25 5:17 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 834 bytes --]
"J-P. Rosen" <rosen@adalog.fr> wrote in message
news:t6iad4$263$1@dont-email.me...
> 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 ;-)
An individual aspect can only be specified once per entity, so specifying it
in both is obviously illegal. One would have to check the exact wording to
ensure that it really said that, but surely that would be the intent.
Randy.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Aspect location in expression function.
2022-05-24 18:24 ` G.B.
@ 2022-05-25 5:20 ` Randy Brukardt
2022-05-25 18:45 ` G.B.
0 siblings, 1 reply; 8+ messages in thread
From: Randy Brukardt @ 2022-05-25 5:20 UTC (permalink / raw)
"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" and just let the
compiler complain if you don't give a body for something abstract, but it's
generally recommended to know what you're doing and not just try to make the
compiler happy.
Randy.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Aspect location in expression function.
2022-05-25 5:20 ` Randy Brukardt
@ 2022-05-25 18:45 ` G.B.
0 siblings, 0 replies; 8+ messages in thread
From: G.B. @ 2022-05-25 18:45 UTC (permalink / raw)
On 25.05.22 07:20, Randy Brukardt wrote:
> "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),
Another, dare I say, more frequent way of being a client of a type
is being a caller of the type's subprograms, such as P, rather than
being an implementer of a type's concrete behavior. (The two can
overlap, but I'm thinking of the more frequent human clients here :) )
A case I'd single out is a type that comes with a factory F.
I'd expect the associated type T to be abstract. This goes
without saying! ;-) A client needs to know the "behavioral"
interface of T and also that of F.
The "is abstract" then remains as helpful language technology,
but as seen inside the factory.
(So, I'd put "is abstract" last.)
> especially as "abstract" routines mostly are used with root types (and
> interfaces). I suppose you could "program by error"
Not design errors, but mechanical errors duly output by the compiler.
The programmer will be programming by "following the language's rules".
IDEs and compilers will assist the programmer who is implementing
an abstract type. For example, the usual IDE has this suggestion
following its compiler's error message::
Fix: "Add unimplemented methods"
(for)
Error: "The type must implement[!] the inherited abstract method ..."
The IDE will do so if you answer "Yes" and programmers can provide their
own adjustments to template text that this mechanism will be using. Thus,
again, programmers can involve useful language technology in
a template's text. I remember some Ada tools offering similar features.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-05-25 18:45 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-14 11:47 Aspect location in expression function Blady
2022-05-14 15:40 ` J-P. Rosen
2022-05-24 4:05 ` Randy Brukardt
2022-05-24 10:01 ` J-P. Rosen
2022-05-25 5:17 ` Randy Brukardt
2022-05-24 18:24 ` G.B.
2022-05-25 5:20 ` Randy Brukardt
2022-05-25 18:45 ` G.B.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox