Re: Wishlist
- Posted by Irv Mullins <irvm at ellijay.com> Jun 28, 2001
- 561 views
On Thursday 28 June 2001 01:34, Tony Bucholtz wrote: > I don't think anyone wants to change the value of the loop variable > *inside* the loop. The suggestion is for another way to set the > value of the loop variable *prior* to its use inside the loop. > Ferinstance, if I wanted to process only certain elements of a > sequence, I'd have to use something like: > > sequence seqindex > seqindex = {3, 5, 10, 21, 22, 40, 45, 50, 63} > for i = 1 to length(seqindex) > seq2process[seqindex[i]] = <something> > end for > > The suggestion is for an easier way to do this sort of work, eg: > > foreach i = {3, 5, 10, 21, 22, 40, 45, 50 ,63} > seq2process[i] = <something> > ? i > end foreach OK, now I understand what you're asking. And, as it turns out, I use that kind of thing sometimes, for example, printing notices to past due accounts, extracted from a list of accounts. Here's a simple demo: procedure PrintMe(object x) ? x -- do anything you want here end procedure procedure foreach(sequence list, atom rtn) for i = 1 to length(list) do call_proc(rtn,{list[i]}) end for end procedure foreach({1,4,7,8},routine_id("PrintMe")) Problems with this include the necessity of writing both a foreach procedure and a foreach function, they are not interchangeable. And, if foreach() is made part of a library, the "include foreach.e" has to appear AFTER the PrintMe() routine, so that it can"see" the user-written PrintMe() routine. A built-in foreach() would be nice. Regards, Irv