comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Ada2012 : When to use expression functions rather than function bodies?
Date: Mon, 19 Dec 2011 17:34:42 -0600
Date: 2011-12-19T17:34:42-06:00	[thread overview]
Message-ID: <jcohmk$lc2$1@munin.nbi.dk> (raw)
In-Reply-To: 1xbajufyxdf4j.1moa6g6ouhykk$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:1xbajufyxdf4j.1moa6g6ouhykk$.dlg@40tude.net...
> On 17 Dec 2011 12:45:38 GMT, georg bauhaus wrote:
...
>> I'm guessing that Dmitry will suggest
>>
>>   Procedure Do_It (A, B: Int_Sats_Pre) with
>>     Pre => True;
>>
>> will be safer and will convey the idea
>> of the precondition better: it is in the type system.
>
> Not really. The key question is whether Do_It_Precondition is statically
> checkable. Note also that it is not always possible to break a [true]
> precondition into a set of *independent* subtype constraints.

Right. We had this (sub)discussion in the ARG. It seemed better to extend 
subtype constraints for parameters rather than the heavier mechanism of 
preconditions. But the counter argument is that a constraint can act only on 
a single parameter, while a precondition might involve multiple parameters. 
Dmitry shows a good example.

BTW, we recently added a rule stating that it is a bounded error to call a 
function from a contract (precondition, predicate, etc.) that has a side 
effect that changes the value of some other contract of the same evaluation. 
The latter part is a sop to the people who insist that we have to support 
"benign" side-effects (such as "memo functions"). (IMHO, there are no benign 
side-effects, but there are strong opinions to the contrary out there.)

The effect is that the vast majority of contracts will be "pure" 
expressions, so Dmitry will be happier. (The state-of-the-art will not allow 
static checking of these things today in general, but as the technology 
improves that should become possible without having to rewrite your code).

                                                   Randy.





      reply	other threads:[~2011-12-19 23:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16 12:25 Ada2012 : When to use expression functions rather than function bodies? Martin
2011-12-16 13:24 ` Dmitry A. Kazakov
2011-12-17  1:03   ` Randy Brukardt
2011-12-16 18:03 ` Adam Beneschan
2011-12-16 20:36   ` Martin Dowie
2011-12-16 21:34     ` Adam Beneschan
2011-12-16 23:08       ` Adam Beneschan
2011-12-17 12:26   ` georg bauhaus
2011-12-16 22:01 ` Jeffrey Carter
2011-12-16 22:52   ` Adam Beneschan
2011-12-16 23:09     ` Adam Beneschan
2011-12-17  1:21     ` Randy Brukardt
2011-12-17 12:45       ` georg bauhaus
2011-12-17 13:11         ` Dmitry A. Kazakov
2011-12-19 23:34           ` Randy Brukardt [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox