#313 Allow combining do...over with do..i=...

None
open
nobody
None
none
5
2012-12-24
2008-08-19
Anonymous
No

Currently the do/loop keyword only accepts either the variant "DO obj OVER coll" or the classic "DO i=1 [TO...]".

Combining the two forms by delimiting them with a comma, would alleviate some recurrent coding needs from the programmer.

E.g. two use cases:

1) Many times looping over collections incurs getting the item number at hand:

aList=.list~of("a", "c", "b", "d")
do obj over aList, i=1
   say "#" i":" obj
end

Would yield:

# 1: a
# 2: c
# 3: b
# 4: d

2) In addition, sometimes only some top number of objects should be processed in a do..over loop.

aQueue=.queue~of("q", "m", "r", "t", "a", "v")
loop obj over aQueue, i=1 to 3
say i":" obj
end

Would yield the first three queue objects:

1: q
2: m
3: r

fgr

Discussion


Anonymous


Cancel   Add attachments