2

i've been trying a lot of things and looking for solutions but i can't find one.

I' m stuck because i need to assign a new value to a post condition in an ada function

For example, with the following function:

function Square(A: in out INTEGER) return INTEGER
   with 
      Pre => A > 0,
      Post => Square'Result = A * A
....

I would like to know how i can for example increment the parameter A or set it to a random value like 42 inside of the the post condition

Thank you

  • 1
    You can use A'Pre and A'Post to use value of A before or after execution of function. I don't believe it to be possible to actually change the value of A inside a contract... – darkestkhan Mar 28 '21 at 10:37
  • thanks for your response, i've just found the answer by testing things – Alexis Guillot Mar 28 '21 at 11:02
  • Please explain what you found by "testing things". Perhaps you could also clarify what your original problem was, because I certainly did not understand what you wanted to do; pre- and post-conditions are conditions, they are not expected to change the values of any variables. – Niklas Holsti Mar 28 '21 at 11:39
  • 2
    To darkestkhan: I think your comment is wrong. Within a precondition, the name A refers to the value of A before the subprogram is executed; within a postcondition, the name A refers to the value of A after the execution. In a postcondition, and only there, one can use A'Old to refer to the value A had before the subprogram execution. – Niklas Holsti Mar 28 '21 at 11:59
  • @NiklasHolsti indeed. It is X, X'Old and F'Result. – darkestkhan Mar 29 '21 at 17:06

0 Answers0