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-Thread: 103376,61e9062c1f23b9d5 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.germany.com!news.belwue.de!th!lucks From: Stefan Lucks Newsgroups: comp.lang.ada Subject: Re: Reconsidering assignment Date: Thu, 7 Jun 2007 09:10:25 +0200 Organization: InterNetNews at News.BelWue.DE (Stuttgart, Germany) Message-ID: References: <1181165630.012508.55290@i38g2000prf.googlegroups.com> NNTP-Posting-Host: th.informatik.uni-mannheim.de Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: news.BelWue.DE 1181200227 21020 134.155.91.85 (7 Jun 2007 07:10:27 GMT) X-Complaints-To: news@news.belwue.de NNTP-Posting-Date: Thu, 7 Jun 2007 07:10:27 +0000 (UTC) In-Reply-To: <1181165630.012508.55290@i38g2000prf.googlegroups.com> Xref: g2news1.google.com comp.lang.ada:16085 Date: 2007-06-07T09:10:25+02:00 List-Id: On Wed, 6 Jun 2007, Maciej Sobczak 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. Note that the Constraint_Error is raised at the caller's side, after it got the subprogram's response. So calling Swap(X,Y) with X: integer := -1; and Y: Natural := 1; gives you exactly the same "result" as, say, Y := X*Y. You (the caller) are responsible for maintaining the subtypes constraints -- and thus for raising the exception ... > 2. String. This issue is different from (Of course, this generalises to all types with constraints ...). The difference is that the exceptions are raised inside the subprogram, so the caller would need the details of the subprograms implementation to predict if an exception will be raised. That is bad! 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); over > 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 ... Assignment: Do_Something(X: T, Y: X'Type, <... other params ...>) is begin ... -- here you can use X := Y or Y := X without raising Constraint_Error -- except, of course, T is limited end Do_Something; > 3. Tagged types. > procedure Safe_Swap(X, Y : in out Object'Class) with X'Tag = Y'Tag; procedure Safe_Swap(X: in out Object'Class; Y: X'Type) is > declare > T1 : Triangle := ...; > T2 : Triangle := ...; > C : Circle := ...; > begin > Safe_Swap(T1, T2); -- OK > Safe_Swap(T1, C); -- compile-time error > end; Comments? -- Stefan Lucks (moved to Bauhaus-University Weimar, Germany) ------ I love the taste of Cryptanalysis in the morning! ------