For reference, here is an in-place version: : shift-down ( seq -- ) [ but-last 1 ] keep copy ; : rotate ( seq -- ) [ peek ] [ shift-down ] [ ] tri set-first ;
It rotates the entire sequence. To rotate a subsequence, call rotate on a slice, eg 5 head-slice rotate Slava On Mon, Feb 23, 2009 at 12:19 PM, Daniel Ehrenberg <[email protected]> wrote: > Well, here's an inefficient way to do it, but the code is pretty: > > : move-to-end ( n seq -- newseq ) > [ remove-nth ] [ nth ] 2bi suffix ; > > I guess you could make this all in place to be more efficient, but > asymptotically this wouldn't really be a win in terms of time (unless > the index you provide is usually near the end). If you want to do this > particular operation efficiently, I suggest you use dlists. But if > your problem is really to apply a particular permutation to a > sequence, using a word like this might be the best way to go: > > : map-permutation ( seq permutation -- newseq ) > swap '[ _ nth ] map ; > > I'd give you a code sample of how to calculate your permutation, but > I'm not sure exactly what you want to do here. > > Dan > > On Mon, Feb 23, 2009 at 10:05 AM, Jon Kleiser <[email protected]> wrote: >> Hi, >> >> Could somebody tell me the most efficient way to cut an element out of a >> sequence and put it at the end? I need to repeat this over and over, but >> each time with a new index. If the index e.g. runs from 1 to 3, the >> results should be like this: >> >> initial { a b c d e f } >> 1 -> { a c d e f b } >> 2 -> { a c e f b d } >> 3 -> { a c e b d f } >> >> Sincerely, >> >> Jon Kleiser >> >> ------------------------------------------------------------------------------ >> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA >> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise >> -Strategies to boost innovation and cut costs with open source participation >> -Receive a $600 discount off the registration fee with the source code: SFAD >> http://p.sf.net/sfu/XcvMzF8H >> _______________________________________________ >> Factor-talk mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/factor-talk >> > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Factor-talk mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/factor-talk > ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Factor-talk mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/factor-talk
