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!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 05 Sep 2015 07:07:24 -0500 From: Peter Chapin Newsgroups: comp.lang.ada Subject: Re: Top 10 Worst C# Features Date: Sat, 5 Sep 2015 08:07:24 -0400 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit User-Agent: MicroPlanet-Gravity/3.0.4 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-i8Q6xQ+944ZYi9WVE3oQPGeIeMA+r3ccBnReZ8ywIPI8CGzKxVwQTklgu+vKgDGUZEabayCwUOBgoEp!ATgsRqNP+ofVANqwnuHIaBhZH2spvy6YbveQ/pVM989lmL2wnfvVzYPlguOhbxON1UgYB7sVWg== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3362 X-Received-Bytes: 3474 X-Received-Body-CRC: 915668134 Xref: news.eternal-september.org comp.lang.ada:27711 Date: 2015-09-05T08:07:24-04:00 List-Id: In article , niklas.holsti@tidorum.invalid says... > I have long wished for an easier way to return multiple results from a > call, especially when the set of results that is really available > depends on the run-time outcome of the call, for example on whether the > called operation succeeded or failed in some way. Functional languages have thought about this. Most provide a way of defining a kind of variant record with very lightweight syntax so defining a new record for each use isn't onerous. As an example Scala (for instance) has an Option type in its library specifically for use by functions that may not have a valid value to return. A function that might or might not return an integer can be declared to run an Option[Int] (like a generic instance) that either holds the integer in question or has the special value None. This can be simulated in Ada without too much pain but what makes functional languages different is that it is easy to define and use variations of this idea without a lot of ceremony. > Then it should be possible to call a procedure in a way that opens a > block that implicitly starts with a case statement and separates into > different branches for different outcomes... This is done using pattern matching in functional languages which, as you observe, complements the features above very nicely. Actually Scala provides higher order methods on the Option type that allows you, in that case, to operate on data that might or might not be there without worrying about checking for its existence until the last minute. This pushes error handling out of the main logic of your program without using exceptions for that purpose. I'm not sure how possible it would be to retrofit these ideas into Ada. I'm going to guess it would be hard. Ada is not a functional language and as soon as you start walking down the path I'm talking about here you end up dragging in a lot of the usual functional machinery. Peter