--- ai05s/ai05-0176-1.txt 2010/12/15 00:10:58 1.20 +++ ai05s/ai05-0176-1.txt 2011/01/27 06:06:16 1.21 @@ -3394,3 +3394,80 @@ **************************************************************** +From: Christoph Grein +Sent: Thursday, November 18, 2010 1:15 AM + +!topic AI05-0147-1 AI05-0176-1 +!reference Ada 2005 RM-4.5.7(5.3), RM-4.5.9(4/3) +!from Author Grein 2010-11-18 +!keywords while loop conditional_expression quantified_expression +!discussion +Quote RM-4.5.9(4/3): "Wherever the Syntax Rules allow an expression, a +quantified_expression may be used in place of the expression, so long as +it is immediately surrounded by parentheses." + +Suppose P (X) is some boolean expression. Then: + +while (for all X in A'Range => P (X)) loop -- ugly, but understandable + +while (for some X in A'Range => P (X)) loop -- what should this mean? + +Also conditional expressions look bad in this context. Is this really +the intent? + +**************************************************************** + +From: Edmond Schonberg +Sent: Thursday, November 18, 2010 8:43 AM + +> while (for some X in A'Range => P (X)) loop -- what should this mean? + +Exactly what it says: iterate as long as there is at least one element in the +range of A that satisfies the predicate. The existentially quantified expression +is a boolean condition, evaluated each time through the loop. + +**************************************************************** + +From: Cyrille Comar +Sent: Thursday, November 18, 2010 9:21 AM + +> Suppose P (X) is some boolean expression. Then: +> +> while (for all X in A'Range => P (X)) loop -- ugly, but +> understandable + +the "while" loop continues as long as P(A'First) .. P(A'Last) are all true and +stops as soon as one of those is false + +> while (for some X in A'Range => P (X)) loop -- what should this mean? + +the "while" loop continues as long as there is at least one in +P(A'First) .. P(A'Last) that is true and stops when they are all false. + +> Also conditional expressions look bad in this context. Is this really +> the intent? + +if this was what you intended to express, it looks to me that it is a pretty +good way to express it. The "old" way of expressing the same thing is much more +verbose and not particularly readable: + +while (All_Are_True (A, P'Access)) loop ... + +while (One_Is_True (A, P'Access)) loop ... + +where + +function All_Are_True (A : Type_of_A; P : access function (X : type_of_X) return Boolean) is +begin + for I in A'Range loop + if not P.all (I) then + return False; + end if; + end loop; + return True; +end All_Are_True; + +etc... + +**************************************************************** +

Questions? Ask the ACAA Technical Agent