Round Robin with Token Pool

General APL language issues

Round Robin with Token Pool

Postby paulmansour on Tue Jun 21, 2016 1:34 pm

Consider repeatedly selecting an item from a list where we always want the next item, and we reach the end, we go back to the beginning, a round-robin selection.

If we take the list and chuck it into the token pool:

      'ABCDE' ⎕TPUT¨5


And then get and put at the same time:

      f←{r⊣(r←⎕TGET 5) ⎕TPUT 5}


We can select via a round robin method:

      f 0
A
f 0
B
f 0
C
f¨⍳10
DEABCDEABC


I thought this might be an overkill use of the token pool, but I think it might be faster than any other technique, and also avoids deciding where to store the list.

I am continually amazed at how I managed to live before the token pool came in to existence!
paulmansour
 
Posts: 343
Joined: Fri Oct 03, 2008 4:14 pm

Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest