Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: [series//move] Series manipulation Help

From: greggirwin::mindspring::com at: 9-Nov-2004 11:38

Hi Charles, WC> Lst: ["Charlie" 120912 "Peter" 239823 "Sam" 9238923 "Tiana" 92348] WC> I want to find "Sam" and retrieve his ID WC> I them want to remove Sam his ID from Lst: and append it to the end of WC> Lst: I started tinkering with something a while back that may be useful to you. Consider it a starting point if nothing else. move: func [ "Moves the first instance of value, if found, to a new position in the series." series [series!] value /head "Move to the head of the series" /tail "Move to the tail of the series" /to "Move to an absolute position in the series" index [number! logic! pair!] "Can be positive, negative, or zero" /skip "Move forward or backward from the current position" offset [number! logic! pair!] "Can be positive, negative, or zero" /part "Move the given number of items" range [number! series! pair!] ;/all "move all instances of value" ; ??? /local pos dest sw* ] [ sw*: system/words either none? pos: find/only series value [none] [ either part [ value: copy/part pos range remove/part pos range ][ value: first pos remove pos ] dest: any [ all [head sw*/head series] all [tail sw*/tail series] all [to at series index] all [skip sw*/skip pos offset] ] either part [insert dest :value] [insert/only dest :value] ] ] Anyone else who wants to improve it, please do so; or let me know what doesn't work--or what you don't like--and I'll make notes here. -- Gregg