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,bbb3407847759c29 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-14 08:16:56 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: Charles: missing default values Date: 14 Nov 2002 08:16:56 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0211140816.49731152@posting.google.com> References: <3dd32396$0$308$bed64819@news.gradwell.net> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1037290616 7976 127.0.0.1 (14 Nov 2002 16:16:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 14 Nov 2002 16:16:56 GMT Xref: archiver1.google.com comp.lang.ada:30882 Date: 2002-11-14T16:16:56+00:00 List-Id: porton@ex-code.com (Victor Porton) wrote in message news:<3dd32396$0$308$bed64819@news.gradwell.net>... > It is reasonable to add default values to the arguments of > many functions in charles, e.g. Genereic_Find for vectors would > become: > > generic > with function Predicate (Element : Element_Type) > return Boolean is <>; > function Generic_Find > (Container : Container_Type; > First : Index_Type'Base := First(C); > Back : Index_Type'Base := Last (C)) return Index_Type'Base; This won't compile. Where is C defined? This isn't even correct, because the default value for Back is Last (C), which is incorrect. Note that there is a non-generic version of Find, that works by comparing elements using the equality operator for Element_Type. If you want an instantiation of Find that accepts only the container as a parameter, then why don't you simply use a nesting subprogram: function Find (V : Vector_Subtype) return Index_Subtype'Base is procedure Find is new Generic_Find (Predicate); begin return Find (V, First (V), Back (V)); end; Note also that this is a linear search. If your vector is sorted, then you should be using Binary_Search or Lower_Bound.