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

Blocks of Strings

 [1/4] from: louisaturk::coxinet::net at: 5-Nov-2002 0:04


Hi rebols, 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? Thanks, Louis

 [2/4] from: tomc:darkwing:uoregon at: 4-Nov-2002 23:13


one way
>> x: ["dsfrghtr" "gfdh" "sdfjhf" "jkhkah" "dsfkas" "hfkh" "dsfkjsa"
hdfklhSDF "KHJKSFH"] == ["dsfrghtr" "gfdh" "sdfjhf" "jkhkah" "dsfkas" "hfkh" "dsfkjsa" hdfklhSDF "KHJKSFH"]
>>Y: []
== []
>> foreach [a b c] x [append/only y reduce[a b c]]
== [["dsfrghtr" "gfdh" "sdfjhf"] ["jkhkah" "dsfkas" "hfkh"] ["dsfkjsa" hdfklhSDF "KHJKSFH"]] On Tue, 5 Nov 2002, Louis A. Turk wrote:

 [3/4] 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/"
<<quoted lines omitted: 4>>
> 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 ]

 [4/4] from: louisaturk:coxinet at: 7-Nov-2002 1:59


Hi Tom and Andrew, Many thanks for several ways to do this. Very interesting. Step by step I'm getting where I need to go. Louis At 08:28 PM 11/5/2002 +1300, you wrote:

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted