On Thu, 2003-04-03 at 07:08, Art Eschenlauer wrote:
> Dear Uniconers:
>
> For a particular program that I am writing, I created a class (OList,
> see code at end of message) to manage a list. If anyone knows of a
> better or more general implementation, I'd like to hear about it.
>
> Anyway, I am looking at the l_reorder() method, which moves the list
> item at position specified by the first argument to the position
> specified by the second argument. To clarify what I mean,
> object := OList( [1,2,3,4,5] )
> # object.data is now [1,2,3,4,5]
> # next, move data[-2:+1] to the position data[2]
> object.l_reorder( -2, 2 )
> # object.data is now [1,4,2,3,5]
>
> My question is, "Is there a way to do this that is more straightforward
> than using delete and insert?" For instance, exchanging items could
> straightforwardly be coded in a method body as
> return (data[imove] :=: data[ib4]) & 1
> but I cannot think of an equally terse way of moving a data item.
Interesting problem. I don't think the following approach is terser,
but it *might* be faster...on 'short' moves (someone should time it...)
*Danger, Will Robinson. Untested code follows...*
p1 := imove-1
p2 := ib4
dir := -1
if ib4 > imove then {
p1 := imove
p2 := ib4-1
dir := 1
}
every data[p := (p1 to p2 by dir)] :=: data[p+1]
--
Steve Wampler <[EMAIL PROTECTED]>
National Solar Observatory
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group