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!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: "functional" programming in Ada Date: Tue, 6 Mar 2018 14:17:34 -0600 Organization: JSA Research & Innovation Message-ID: References: <83978b21-9384-4b04-a16d-37ce06488800@googlegroups.com> Injection-Date: Tue, 6 Mar 2018 20:17:34 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="28503"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:50856 Date: 2018-03-06T14:17:34-06:00 List-Id: "Mehdi Saada" <00120260a@gmail.com> wrote in message news:cd48925d-5cac-465c-96c3-a392f0ce4079@googlegroups.com... >> From a compiler writer POV I may understand it for the same reasons we >> have the private part in the spec. > How come ? Why should the compiler handle those functions differently > than normal functions whose body is forbidden to be anywhere else than in > the package body ? It helps other (non-Ada) tools; in particular proof and analysis tools, if the entire details of a precondition/postcondition are available to the tools (and without depending on contents of bodies). This literally led to preconditions that were many pages long. Expression functions were introduced in part to allow some abstraction in contracts without hiding the details of thosee contracts from the tools. Secondarily, a compiler can take advantage of these for better inlining and better optimization of contracts. [The real reason I was interested.] They also open up some other possibilities (not all taken advantage of yet): user-defined static expressions; default implementation of functions for interfaces; anonymous functions to pass for one-time use parameters. Generally, I'd expect them to appear mainly in private parts, because the visible spec shouldn't include enough info to be able to usefully implement much -- you usually need access to the components of the central private type in order to write such a function. They *are* tempting to use, especially in quick-and-dirty code (like ACATS tests). I've found myself having to remove them from tests that are supposed to work on Ada 95 or Ada 2005. Randy.