comp.lang.ada
 help / color / mirror / Atom feed
* calling function but ignoring results
@ 2021-06-29 19:25 Matt Borchers
  2021-06-29 19:52 ` Jeffrey R. Carter
                   ` (3 more replies)
  0 siblings, 4 replies; 28+ messages in thread
From: Matt Borchers @ 2021-06-29 19:25 UTC (permalink / raw)


It is not very often that ignoring a function result is okay, but I have run across many instances of the following block structure in code over the years:

declare
    dont_care : BOOLEAN;
begin
    dont_care := foo( x, y );
end;

I also see the procedure wrapper used in some cases -- usually when exported in a package specification:

procedure FOO( x, y ) is
    b : BOOLEAN;
begin
    b := foo( x, y );
end FOO;

The procedure adds nothing to the code except another thing to maintain when the function interface needs modification.

Is there a Ada 202x feature to support calling functions and ignoring the result?  If not, I'm wondering if the @ symbol recently introduced for assignments could be used?  How would people feel about the following?

@ := foo( x, y );

This would discard the result of the function.  This could obviously lead to memory leaks (without reference counting), but the syntax could be restricted for use on functions that do not return uncontrolled access types or these functions could be marked with a keyword to make it legal for it to be called in such a way when the programmer knows that the access returned should not be "freed" by the caller (such as a pointer into an existing structure).

I have not given this much thought so I'm sure there are reasons why this can't (or shouldn't) be done in general.  Regardless, there are probably many that would agree with me that the declare block and the wrapper procedure options are annoying and could be considered superfluous for lack of a better way to write the code more simply.

Matt

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2021-07-12 15:56 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 19:25 calling function but ignoring results Matt Borchers
2021-06-29 19:52 ` Jeffrey R. Carter
2021-06-29 20:34   ` Dmitry A. Kazakov
2021-06-30  6:06     ` Randy Brukardt
2021-07-09 18:14       ` G.B.
2021-07-09 19:20         ` Niklas Holsti
2021-07-10  2:57           ` Randy Brukardt
2021-07-12 15:56         ` Shark8
2021-06-30 10:17   ` Luke A. Guest
2021-07-01 18:07   ` Gabriele Galeotti
2021-07-02  7:32     ` Marius Amado-Alves
2021-07-03 11:35       ` Gabriele Galeotti
2021-07-03 11:46       ` Gabriele Galeotti
2021-07-03 19:11         ` Simon Wright
2021-07-04  7:22           ` Simon Wright
2021-07-06 23:07           ` Randy Brukardt
2021-06-30 10:26 ` Luke A. Guest
2021-06-30 19:31   ` Simon Wright
2021-06-30 23:06   ` Rod Kay
2021-07-01  0:06 ` Stephen Leake
2021-07-01  3:55   ` Randy Brukardt
2021-07-03 10:42     ` Stephen Leake
2021-07-03  1:22 ` Nasser M. Abbasi
2021-07-03  4:59   ` Matt Borchers
2021-07-03  7:37     ` Gautier write-only address
2021-07-03  7:42       ` Gautier write-only address
2021-07-03  7:57       ` Niklas Holsti
2021-07-03  7:46   ` Gautier write-only address

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox