Warwick Harvey wrote: > > There appears to be a bug with regard to counting conditions in do loops. I > would have assumed that if I had `for(I, 1, 3)' as a condition for a do > loop, the loop would not have iterated more than 3 times. This is not the > case, as shown in the example below. The same thing happens using `count' > instead of `for', and using a `fromto' instead of a `foreach'. The loop terminates iff all the termination conditions are true. The loop continues if all the termination conditions are false. Otherwise, depending on the exact condition - it continues - it fails but it never terminates with success. In your example, the only other implementable behaviour is failure after 3 instead of failure after 5 iterations. Even though we could "fix" the for-condition (at a cost), in general we cannot get rid of the fail/continue ambiguity because we allow the general fromto-condition. Look at a single fromto and the decision of whether to continue or terminate (at the very start of the iteration): continue terminate fromto([a],[_|T],T,[]) y n fromto( [],[_|T],T,[]) n y fromto( _,[_|T],T,[]) y y fromto([a], _ ,T,[]) y n fromto( [], _ ,T,[]) * y y fromto( _, _ ,T,[]) y y There are sensible fromtos that are ambiguous. In your example, after 3 iterations, the for-condition (corresponding to the fromto marked with *) makes a y-y decision, the foreach makes a y-n decision, and the result is continuation. The other possibility would have been a n-y and a y-n which would have led to immediate failure. So is it worth changing the behaviour of for and count, given that you can still get the bahaviour with fromto? -- JoachimReceived on Thu Sep 20 21:09:08 2001
This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:08:10 PM GMT GMT