comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: on the need to duplicate code for procedure signature in both body and interface files
Date: Fri, 13 Jul 2012 11:51:07 -0400
Date: 2012-07-13T11:51:07-04:00	[thread overview]
Message-ID: <wccliin8xsk.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: jtb87i$2io5$1@adenine.netfront.net

Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:

> Consider the following:
>
> package P is
>    function F (I : Integer) return Integer;
>
>    type Integer_List is array (Integer range <>) of Integer;
>
>    function F return Integer_List;
> end P;
>
> How are you going to write the body of P so the compiler knows which
> body implements which function F without repeating the parameter list
> and return type profile, which is what distinguishes these 2 overloaded
> functions?

Well, that wouldn't be too hard of a problem to solve.
I think the real reason for duplicating the information
is readability.

For example, you could require that two functions in the same scope
have different names.  You could still use overloading via
renames:

   function F_Integer (I : Integer) return Integer;
   function F (I : Integer) return Integer renames F_Integer;
   ...
   function F_Integer_List return Integer_List;
   function F return Integer_List renames F_Integer_List;

I tend to use this style anyway, because then the debugger
tells me which function I'm in.  Also, if this were the rule,
the compiler could more easily give good error messages.
Consider:

    procedure P (X : Integer);
    ...
    procedure P (X : Long_Integer) is -- Wrong.
    begin
        ...
    end P;

where the mistake is that I changed Integer to Long_Integer
in one place but forgot the other.  A typical compiler will
complain incorrectly that P doesn't have a body.

One could facilitate the above renamings with a shorthand:

   function F_Integer, F (I : Integer) return Integer;
   function F_Integer_List, F return Integer_List;

- Bob



  reply	other threads:[~2012-07-13 15:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-07 23:08 on the need to duplicate code for procedure signature in both body and interface files Nasser M. Abbasi
2012-07-08  4:01 ` Shark8
2012-07-08 17:13   ` Brian Drummond
2012-07-08  4:21 ` Niklas Holsti
2012-07-08  6:09 ` Jeffrey Carter
2012-07-13 15:51   ` Robert A Duff [this message]
2012-07-08  7:38 ` Stephen Leake
2012-07-08 10:52 ` Manuel Collado
2012-07-09  1:48 ` Britt
2012-07-09 10:49   ` AdaMagica
2012-07-09 15:11 ` Adam Beneschan
2012-07-13 17:12 ` björn lundin
replies disabled

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