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!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.unit0.net!news.uni-stuttgart.de!news-1.dfn.de!news.dfn.de!news.uni-weimar.de!medsec1.medien.uni-weimar.de!lucks From: Stefan.Lucks@uni-weimar.de Newsgroups: comp.lang.ada Subject: Re: Community Input for the Maintenance and Revision of the Ada Programming Language Date: Fri, 11 Aug 2017 09:57:25 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <1395655516.524005222.638450.laguest-archeia.com@nntp.aioe.org> <1502382504.2184.6.camel@obry.net> <466561720.524077501.729508.laguest-archeia.com@nntp.aioe.org> NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-1468562027-1502436716=:23919" X-Trace: pinkpiglet.scc.uni-weimar.de 1502438246 10345 141.54.178.228 (11 Aug 2017 07:57:26 GMT) X-Complaints-To: news@pinkpiglet.scc.uni-weimar.de NNTP-Posting-Date: Fri, 11 Aug 2017 07:57:26 +0000 (UTC) X-X-Sender: lucks@debian In-Reply-To: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Content-ID: Xref: news.eternal-september.org comp.lang.ada:47700 Date: 2017-08-11T09:57:25+02:00 List-Id: --8323329-1468562027-1502436716=:23919 Content-Type: text/plain; CHARSET=ISO-8859-15; FORMAT=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Content-ID: >> Speaking of evil, anonymous types are evil. Why is it hard to declare a >> record type for this purpose? > > A record is mutable, a tuple isn't meant to be mutable > (i.e., can't update it's components). I don't think, supporting function returning ad-hoc anonymous tuples would= =20 strengthen Ada's stand as a language well-suited for safe and secure=20 systems. Anonymous types are bad in that area, anyway. If you want tuples, then it would be a lot more consistent to actually=20 propose the introduction of tuples (i.e., constant records) into the Ada=20 type system, e.g., type May_Be_Integer(Valid: Boolean :=3D True) is constant record case Valid is =09when True =3D> Value: Integer; =09when False =3D> null; end case; end record; type Numeric(Is_Float: Boolean :=3D True) is constant record case Is_Float is =09when True =3D> F: Float; =09when False =3D> I: Integer; end case; end record; Then you can the kind of functions you are requesting: function Calculate(A, B, C: Integer; D, E, F: Float) return Numeric; -- returns either Integer or Float but you can also deal with such tuples in a really consistent way. This=20 could look about as follows: Not_An_Int: May_Be_Integer(False); function May_Be(I: Integer) return May_Be_Integer is (May_Be_Integer(Value =3D> I)); function "+"(A, B: May_Be_Integer) return May_Be_Integer is begin if A.Valid and B.Valid then return A.Value + B.Value; else return Not_An_Int; end; end "+"; function "*"(A, B: May_Be_Integer) return May_Be_Integer is begin if A.Valid and then A.Value =3D 0 then return 0; elsif B.Valid and then B.Value =3D 0 then return 0; elsif A.Valid and B.Valid then return A.Value * B.Value else return Not_An_Int; end; end "*"; function "-"(A, B: May_Be_Integer) return May_Be_Integer is ... function "/"(A, B: May_Be_Integer) return May_Be_Integer is ... At a first look, this may appear like a convoluted approach to evaluate=20 integer expressions, replacing exceptions by Not_An_Int. But consider an=20 expression like May_Be(1) + (May_Be(2) / May_Be(0)) * May_Be(0) This expression will evaluate to 1, while the corresponding integer=20 expression 1 + (2/0) * 0 will raise an exception. If there is a chance for errors to cancel out, as in my definition of "*", then integers with error markers are a good=20 approach, and exceptions will complicate things a lot. And yes, I know that my multiplication for May_Be_Integer does not match=20 mathematical conventions. Stefan -------- I love the taste of Cryptanalysis in the morning! -------= - www.uni-weimar.de/de/medien/professuren/mediensicherheit/people/stefan-luck= s ----Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universit=E4t Weimar, Germany-= --- --8323329-1468562027-1502436716=:23919--