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

[REBOL] Efficient binary functions, Re:

From: kgd03011:nifty:ne:jp at: 11-Oct-2000 12:19

Hi Phil, This should work:
>> rejoin [v1 v2 v3]
== #{01237B30337D237B34347D} but it doesn't, due to a bug acknowledged by Carl. Until it gets fixed the best I can think of is to use: rejoin-fixed: func [ "Reduces and joins a block of values." block [any-block!] "Values to reduce and join" /local result ][ if empty? block [return ""] either series? result: first block: reduce block [ result: copy :result ][ result: form result ] either any-block? :result [ foreach i next block [ insert tail :result :i ] ][ foreach i next block [ if any-block? i [i: rejoin-fixed i] append result i ] ] :result ]
>> rejoin-fixed [v1 v2 v3]
== #{010344} This "fixed" version of REJOIN shows a couple of other differences, which I think are improvements:
>> rejoin []
** Script Error: Out of range or past end. ** Where: append either series? first block
>> rejoin-fixed []
== ""
>> rejoin [[1 2 3][4 5 6][7 8 9]]
== [1 2 3 [4 5 6] [7 8 9]]
>> rejoin-fixed [[1 2 3][4 5 6][7 8 9]]
== [1 2 3 4 5 6 7 8 9]
>> rejoin-fixed [0 [1 2 3][4 5 6][7 8 9]]
== "0123456789"
>> rejoin [0 [1 2 3][4 5 6][7 8 9]]
== "01 2 34 5 67 8 9"
>> rejoin ['a/b/c 'd/e/f 'g/h/i]
** Script Error: Cannot use path on word! value. ** Where: insert tail series :value
>> rejoin-fixed ['a/b/c 'd/e/f 'g/h/i]
== a/b/c/d/e/f/g/h/i I'd be very grateful to hear opinions or suggestions. Eric