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

[REBOL] Re: Blocks of Strings

From: al:bri:xtra at: 5-Nov-2002 20:28

Louis wrote:
> I have a block of strings in ordered sets of three: > > x: ["Bi,bloj" "bi,bloj" "nnfs" "gene,sewj" "ge,nesij" "ngfs" "VIhsou/" > "VIhsou/j" "ngms"] > > I need to convert it into a block of blocks of strings: > > y: [["Bi,bloj" "bi,bloj" "nnfs"] ["gene,sewj" "ge,nesij" > "ngfs"] ["VIhsou/" "VIhsou/j" "ngms"]] > > What is the best way to do this? >> x: ["Bi,bloj" "bi,bloj" "nnfs" "gene,sewj" "ge,nesij" "ngfs" "VIhsou/"
[ "VIhsou/j" "ngms"] == ["Bi,bloj" "bi,bloj" "nnfs" "gene,sewj" "ge,nesij" "ngfs" "VIhsou/" "VIhsou/j" "ngms"]
>> map/only X func [S1 [string!] S2 [string!] S3 [string!]] [reduce [S1 S2
S3]] == [["Bi,bloj" "bi,bloj" "nnfs"] ["gene,sewj" "ge,nesij" "ngfs"] ["VIhsou/" "VIhsou/j" "ngms"]] Or:
>> y: make block! length? x
== []
>> foreach [S1 S2 S3] X [repend/only y reduce [s1 s2 s3]]
== [["Bi,bloj" "bi,bloj" "nnfs"] ["gene,sewj" "ge,nesij" "ngfs"] ["VIhsou/" "VIhsou/j" "ngms"]] I hope that helps! Andrew Martin ICQ: 26227169 http://valley.150m.com/ -><- -- Attached file included as plaintext by Listar -- -- File: Map.r Rebol [ Name: 'Map Title: "Map" File: %"Map.r" Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Web: http://valley.150m.com Date: 24/September/2002 Version: 1.3.0 Purpose: {Maps or applies the function to all elements of the series.} Category: [util 1] Acknowledgements: [ "Joel Neely" "Ladislav" ] Example: [ Map func [n [number!]] [n * n] [1 2 3] ;== [1 4 9] Map [1 2 3] func [n [number!]] [n * n] ;== [1 4 9] Map [1 2 3 4 5 6] func [a] [print [a]] ;1 ;2 ;3 ;4 ;5 ;6 ;== [] Map [1 2 3 4 5 6] func [a b] [print [a b]] ;1 2 ;3 4 ;5 6 ;== [] Map [1 2 3 4 5 6] func [a b c] [print [a b c]] ;1 2 3 ;4 5 6 ;== [] ] Requires: %Arguments.r ] Map: function [ {Maps or applies the function to all elements of the series.} [catch] Arg1 [any-function! series!] Arg2 [any-function! series!] /Only "Inserts the result of the function as a series." ][ Result Results Function Series ][ throw-on-error [ any [ all [ any-function? :Arg1 series? :Arg2 (Function: :Arg1 Series: :Arg2) ] all [ any-function? :Arg2 series? :Arg1 (Function: :Arg2 Series: :Arg1) ] throw make error! reduce [ 'script 'cannot-use rejoin [ {"} mold 'Map " " mold type? :Arg1 {"} ] rejoin [ {"} mold type? :Arg2 {"} ] ] ] Results: make Series length? Series do compose/deep [ foreach [(Arguments :Function)] Series [ if all [ not unset? set/any 'Result Function (Arguments :Function) not none? Result ] [ (either Only ['insert/only] ['insert]) tail Results :Result ] ] ] Results ] ] -- Attached file included as plaintext by Listar -- -- File: Arguments.r Rebol [ Name: 'Arguments Title: "Arguments" File: %"Arguments.r" Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Web: http://valley.150m.com Date: 31/August/2002 Version: 1.0.1 Example: [ Arguments :Arguments ; [F] ] Purpose: "Returns the arguments of the function as a block." Category: [util script 5] ] Arguments: function [ "Returns the arguments of the function as a block." F [any-function!] ] [ Arguments ] [ Arguments: make block! 2 foreach Argument pick :F 1 [ if refinement? :Argument [ break ] append Arguments :Argument ] Arguments ]