comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: calling function but ignoring results
Date: Tue, 29 Jun 2021 22:34:41 +0200	[thread overview]
Message-ID: <sbg04v$i7i$1@gioia.aioe.org> (raw)
In-Reply-To: sbftm5$1gn$1@dont-email.me

On 2021-06-29 21:52, Jeffrey R. Carter wrote:
> On 6/29/21 9:25 PM, Matt Borchers wrote:
>> 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;
> 
> This sort of thing usually indicates a design problem.

True. But there are exceptions from the rule:

1. Bindings to other languages. You normally have the result and you 
quite often ignore it because it is useless.

2. Side effects of the call. Normally you would overload a function with 
a procedure, like here:

    function Pop (Stack : not null access Stack_Type) return Element;
    procedure Pop (Stack : in out Stack_Type);

But you will have a problem (which BTW the proposal fail to address) 
when overloading is solely on the result:

    function Get (File : File_Type) return Integer;
    function Get (File : File_Type) return Float;
    function Get (File : File_Type) return String;

Now if you wanted to skip an integer in the file you could not do it in 
the proposed way:

    @ := Get (Standard_Input); -- Ambiguous

    @ := Integer'(Get (Standard_Input)); -- Ugly

And of course, as many times proposed before a better syntax would be 
the null statement:

    null <expression>; -- Does not address the problem either

>> Is there a Ada 202x feature to support calling functions and ignoring 
>> the result?
> If you want to use a language that allows this, then you probably 
> shouldn't be developing S/W.

I would not say that pieces like:

    declare
       Ignore : constant Bar := Foo (Baz);
    begin
       null;
    end;

or

   if Foo (X) then null; end if;

are good engineering. But excessive overloading may lead to unexpected 
collisions if you have many parameters with defaults.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2021-06-29 20:34 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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