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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,61e9062c1f23b9d5 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!o5g2000hsb.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Reconsidering assignment Date: Thu, 07 Jun 2007 00:32:02 -0700 Organization: http://groups.google.com Message-ID: <1181201522.974849.163960@o5g2000hsb.googlegroups.com> References: <1181165630.012508.55290@i38g2000prf.googlegroups.com> NNTP-Posting-Host: 137.138.37.241 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1181201523 7371 127.0.0.1 (7 Jun 2007 07:32:03 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 7 Jun 2007 07:32:03 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070601 Red Hat/1.5.0.12-0.1.slc3 Firefox/1.5.0.12,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: o5g2000hsb.googlegroups.com; posting-host=137.138.37.241; posting-account=Ch8E9Q0AAAA7lJxCsphg7hBNIsMsP4AE Xref: g2news1.google.com comp.lang.ada:16087 Date: 2007-06-07T00:32:02-07:00 List-Id: On 7 Cze, 09:10, Stefan Lucks wrote: > > 1. Integer and its subtypes (like Positive). > > An Integer object has some value - and only that. Any subtype of > > Integer is defined within the same space, which means that this only > > thing that Integer has is also subject for the constraint check. In > > other words, *every* modification of the Integer (or subtype of) > > object is potentially violating the constraint. > > Yes, that is what subtypes are for. And if a subprogram delivers you a > value in the types range, but outside the subtype's range, a > Constraint_Error is IMHO the right thing. Yes, but my motivation was to exclude it if the code looks "innocent": function Make_Integer return Integer; function Make_Positive return Positive; declare I : Integer; P : Positive; begin I := Make_Positive; -- OK, looks "innocent", cannot raise P := Make_Integer; -- should be error ("innocent" lies) P := (Positive)Make_Integer; -- OK, beware potential errors end; > > 2. String. > The difference is that the exceptions are raised > inside the subprogram But the rules will then apply inside this subprogram. The rule is simple: "innocent" code should not lie. > so the caller would need the details of the > subprograms implementation to predict if an exception will be raised. In other words, the call-site looks innocent, even though the body of subprogram contains evil code raising exceptions. function Innocent_Looking return Positive is begin return (Positive)Make_Integer; end; declare P : Positive; begin P := Innocent_Looking; -- ? end; This is good point. Maybe introducing exception specifications to subprogram signatures would help (like in Java). Things get interesting... > I like your suggestion, but i would prefer a simpler syntax. Use some > attribute Type in this case. Thus, I would prefer > > procedure Swap (X: in out String; Y: in out X'Type); I don't like it because it introduces artificial assymetry in code (it looks like there is a restriction on Y only, whereas in fact the restriction binds both parameters). But the idea is OK. > > procedure Safe_Swap(X, Y : in out String) with X'Length = Y'Length; > > (BTW, your clause ensures that the lengths of the two strings are > identical, the semantic of X'Type would even ensure X'First = Y'First and > X'Last = Y'Last ... Yes, except that these additional restrictions might not be needed in a given context. But I think it would be good to have this possibility as well, see also Ray's variant with X'Subtype = Y'Subtype. -- Maciej Sobczak http://www.msobczak.com/