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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!feeder.erje.net!1.eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: formal array types and default values Date: Wed, 3 Jan 2018 10:33:31 +0200 Organization: Tidorum Ltd Message-ID: References: <053b2370-5c15-4662-a9e3-e1464de206a1@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net maKXq3sruf5mOxqL8QWuNAQsgpJ2sYFpjvHmkr+x6WnwpoQ604 Cancel-Lock: sha1:vWWPsRPnqZFeCOxEFbZNMrRCCnM= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: reader02.eternal-september.org comp.lang.ada:49723 Date: 2018-01-03T10:33:31+02:00 List-Id: On 18-01-03 02:52 , Randy Brukardt wrote: > "Niklas Holsti" wrote in message > news:faqhpnFljnfU1@mid.individual.net... >> On 17-12-30 23:42 , Mehdi Saada wrote: >>> I have several questions more or less related. [snip] >>> It would be nice to be able to set a default value to an array type >>> in a generic package, equal to a generic object parameter. >> >> Agreed. Possibly this case was forgotten, or prevented by such a generic >> object parameter not being a static value. > > Not really. All of these defaults for for a *type*, not a subtype, so there > is only one per type. (There are thorny semantic problems with per-subtype > defaults, we decided they were not worth the trouble.) Thus, it wouldn't > make sense to specify it for generic formal parameters, as presumably the > actual type already has such a default (and if it doesn't, you can't add one > in the generic unit). I think that Mehdi Saada wanted to be able to set a default value for the components of an ordinary (not formal generic) array type declared /in/ the generic package, using a formal generic object as the default value. For example: generic type T is private; Null_Value : in T; package Foo is type Vector is array (Positive range <>) of T with Default_Component_Value => Null_Value; end Foo; Following the current rules, GNAT rejects this because Null_Value is not (always) a scalar. If the generic formal type T is changed to "type T is range <>", GNAT accepts the generic package declaration, but accepts an instantiation only if Null_Value is given a static expression (this is GNAT GPL 2012 on Mac). The drawback of the current restrictions (when T is private) is that the responsibility for the assignment of a default value for the components of the Vector type is placed on the /client/ of the generic package, who must set the default value for the actual type T. Moreover, it is now impossible to have different default component values for different arrays declared in the generic, because type T can have only one default value. One can imagine, for example, that T represents a value in some algebra that has both a "zero" value (neutral element for addition) and a "one" value (neutral element for multiplication), and that the generic package would like to use "zero" as the default component value for one array type ("array of sums") but use "one" as the default component value for another array type ("array of products"). -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .