From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b1ebfe7f8f5e385d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-02 03:43:39 PST Date: Fri, 02 May 2003 12:43:29 +0200 From: =?ISO-8859-1?Q?Rodrigo_Garc=EDa?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020513 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Generic formal access types References: <3eb01630@epflnews.epfl.ch> <3eb0e397@epflnews.epfl.ch> <1459423.SpdnhGgvRt@linux1.krischik.com> <3eb11a85@epflnews.epfl.ch> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: lglpc31.epfl.ch Message-ID: <3eb24bd7$1@epflnews.epfl.ch> X-Trace: epflnews.epfl.ch 1051872215 128.178.76.8 (2 May 2003 12:43:35 +0200) Organization: EPFL Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news.mailgate.org!news-zh.switch.ch!epflnews.epfl.ch!not-for-mail Xref: archiver1.google.com comp.lang.ada:36844 Date: 2003-05-02T12:43:29+02:00 List-Id: 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.