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

[REBOL] Re: [algorithm] Algorithm challenge: selecting a range from multiple blocks

From: sant4:wanadoo at: 20-Sep-2007 22:38

Ho, hi i give it a try (sorry folks, my code is not tested) Some comments on my code: -First object found is cloned (always) -Last object is cloned (if needed) -all intermediate objects are just inserted as-is in the result block (out) (if only one object is returned, he may be cloned two times before being added) get-subset: func [ data [block!] range [block!] /local obj start rest len ][ out: make block! 50 start: range/1 ;skip data until i found the first object while [start > len: length? data/1/items][ data: next data start: start - len ] ; hey !!! it's the first object (perhaps the only) obj: make data/1 [items: cp at data/1/items start] ; insert objects in the result until there is no rest rest: range/2 - range/1 + 1 while [rest >= len: length? obj/items][ unless len = 0 [ insert tail out obj rest: rest - len ] data: next data obj: first data ] ; may I clone the last object ? if len > rest [ insert tail out make obj [items: cp/part obj/items rest] ] out ] ==Steeve