Subject: Re: Generic formal access types
Date: Fri, 02 May 2003 12:43:29 +0200
Date: 2003-05-02T12:43:29+02:00 [thread overview]
Message-ID: <3eb24bd7$1@epflnews.epfl.ch> (raw)
In-Reply-To: rw2of2l4sn7.fsf@lbrenta.corp.emc.com
Well, it is just that null is a perfectly possible return value for my
function and I did not want to raise an exception to process that case.
In your example however (Get_Element), it makes sense to raise an
exception. But imagine a list of access types, even if some of them have
the value null, you might want to return that value as well (it is not
that they are not in the list).
Anyway, I still think it would be great if I could write something like:
generic
type Pointer is access (<>);
Then, the compiler would be able to check that I am actually
instantiating the package with an access type (something I do not have
in your solution) and I could use the "null" value as well.
Rodrigo
Ludovic Brenta wrote:
> Do you absolutely have to return null in one of the functions of your
> generic package? How about raising an exception instead? Something
> along the lines of:
>
> generic
> type Element (<>) is private;
> package List is
> No_Element_Error: Exception;
> type List is private;
> function Get_Element (L : List) return Element;
> private
> type List is ... ;
> end List;
>
> package body List is
> function Get_Element (L : List) return Element is
> begin
> raise No_Element_Error; -- instead of return null
> end Get_Element;
> end List;
>
> I'm sure you've thought about that, but I'm curious to know why it
> wouldn't work for you.
>
> --
> Ludovic Brenta.
next prev parent reply other threads:[~2003-05-02 10:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-30 18:30 Generic formal access types
2003-04-30 19:27 ` Simon Wright
2003-05-01 8:58 `
2003-04-30 21:42 ` Chad R. Meiners
2003-05-01 9:06 `
2003-05-01 9:58 ` Martin Krischik
2003-05-01 13:00 `
2003-05-02 9:14 ` Ludovic Brenta
2003-05-02 10:43 ` [this message]
2003-05-02 10:50 `
2003-05-01 10:09 `
2003-05-02 1:14 ` tmoran
2003-05-02 9:52 `
2003-05-02 16:18 ` tmoran
2003-05-02 16:57 ` Robert A Duff
2003-05-02 19:39 ` Randy Brukardt
2003-05-05 8:14 `
2003-05-05 16:40 ` Matthew Heaney
2003-05-05 17:34 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox