PR# 12843 New feature 'do_all_with_index' behaves badly

Problem Report Summary
Submitter: randyjohn
Category: EiffelBase
Priority: Medium
Date: 2007/05/23
Class: Bug
Severity: Serious
Number: 12843
Release: recent 6.0
Confidential: No
Status: Closed
Responsible:
Environment: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; AXAR_Corp_Device; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)
Synopsis: New feature 'do_all_with_index' behaves badly

Description
Recently you introduced 'do_all_with_index' and 'do_if_with_index' to ARRAY.  Unfortunately, the index that you pass to the agent is 1 based instead of 'lower' based.
   Randy

p.s. This is how we did it:

	do_all_with_index (a_action: PROCEDURE [ANY, TUPLE [G, INTEGER]]) is
			-- Apply `a_action' to every item.
			-- `a_action' receives item and it's index.
			-- Semantics not guaranteed if `a_action' changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
		require
			a_action_not_void: a_action /= Void
		local
			l_args: TUPLE [G, INTEGER]
			l_cursor: like cursor
		do
			l_cursor := cursor
				
			create l_args
			from
				start
			until
				after
			loop
				l_args.put (item, 1)
				l_args.put (index, 2)
				a_action.call (l_args)
				forth
			end

			go_to (l_cursor)
		end
To Reproduce

										
Problem Report Interactions
From:manus_eiffel    Date:2007/05/23    Status: Closed    Download   
The code was a user contribution. We fixed it in the next release by fixing the current implementation rather than using start/after/forth which might be slower.

	do_all_with_index (action: PROCEDURE [ANY, TUPLE [G, INTEGER]]) is
			-- Apply `action' to every item, from first to last.
			-- `action' receives item and its index.
			-- Semantics not guaranteed if `action' changes the structure;
			-- in such a case, apply iterator to clone of structure instead.
		require
			action_not_void: action /= Void
		local
			t: TUPLE [G, INTEGER]
			i, j, nb: INTEGER
			l_area: like area
		do
			from
				create t
				i := 0
				j := lower
				nb := capacity - 1
				l_area := area
			until
				i > nb
			loop
				t.put (l_area.item (i), 1)
				t.put (j, 2)
				action.call (t)
				j := j + 1
				i := i + 1
			end
		end