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

Efficient binary functions

 [1/5] from: phil:hayes:cnut at: 11-Oct-2000 1:48


This is a multi-part message in MIME format. ------=_NextPart_000_000B_01C03325.5E3D8330 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Suggestions !!! v1: #{01} v2: #{03} v3: #{44} What’s the most efficient way of concatenating v1, v2 and v3 Obviously…I can use: append v1 v2 append v1 v3 However, if I have X vars to concatenate this is unwieldy… Phil Hayes ------=_NextPart_000_000B_01C03325.5E3D8330 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <meta name=ProgId content=Word.Document> <meta name=Generator content="Microsoft Word 9"> <meta name=Originator content="Microsoft Word 9"> <link rel=File-List href="cid:[filelist--xml--01C03325--5BD5AAF0]"> <!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:DoNotRelyOnCSS/> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:DocumentKind>DocumentEmail</w:DocumentKind> <w:EnvelopeVis/> </w:WordDocument> </xml><![endif]--> <style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig {margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} span.EmailStyle15 {mso-style-type:personal-compose; mso-ansi-font-size:10.0pt; mso-ascii-font-family:Arial; mso-hansi-font-family:Arial; mso-bidi-font-family:Arial; color:black;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> </head> <body lang=EN-GB style='tab-interval:36.0pt'> <div class=Section1> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>Suggestions !!!<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>v1: #{01}<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>v2: #{03}<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>v3: #{44}<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>What&#8217;s the most efficient way of concatenating v1, v2 and v3<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>Obviously&#8230;I can use:<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>append v1 v2<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>append v1 v3<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>However, if I have X vars to concatenate this is unwieldy&#8230;<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'>Phil Hayes<o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></font></span></p> <p class=MsoNormal><span class=EmailStyle15><font size=2 color=black face=Arial><span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family: Arial'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></font></span></p> </div> </body> </html> ------=_NextPart_000_000B_01C03325.5E3D8330--

 [2/5] from: larry:ecotope at: 10-Oct-2000 19:09


Hi Phil Don't know about most efficient, but this is probably close: foreach item reduce [v2 v3][append v1 item] HTH -Larry ----- Original Message ----- From: [phil--hayes--cnut--co--uk] To: [list--rebol--com] Sent: Tuesday, October 10, 2000 5:48 PM Subject: [REBOL] Efficient binary functions Suggestions !!! v1: #{01} v2: #{03} v3: #{44} What's the most efficient way of concatenating v1, v2 and v3 Obviously.I can use: append v1 v2 append v1 v3 However, if I have X vars to concatenate this is unwieldy. Phil Hayes

 [3/5] 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

 [4/5] from: joel:neely:fedex at: 10-Oct-2000 22:15


Hi, Phil... I'm quite embarrased to say that the best I've come up with is
>> v1: #{01}
== #{01}
>> v2: #{03}
== #{03}
>> v3: #{44}
== #{44}
>> v0: #{} foreach v reduce [v1 v2 v3] [append v0 v] v0
== #{010344} (Obviously this could be wrapped in a nicely-named function...) All of the obvious things I've tried fall prey to the old "binary values converted to strings in a surprising and mostly useless way" landmine discussed on this list a few days back! -jn-

 [5/5] from: kgd03011:nifty:ne:jp at: 11-Oct-2000 14:28


Hi, Ooops, coupla bug fixes. This thing has gotten a lot more complicated than I'd anticipated. This crashes and burns if the first value in BLOCK is a list, but so does REJOIN. rejoin-fixed: func [ "Reduces and joins a block of values." block [any-block!] "Values to reduce and join" /local result i ][ if empty? :block [return copy ""] either series? result: first block: reduce :block [ result: copy :result ][ result: form result ] block: next :block either any-block? :result [ while [not tail? block][ insert tail :result first block block: next block ] ][ while [not tail? :block][ i: first :block if any-block? :i [i: rejoin-fixed :i] append result :i block: next :block ] ] :result ] Eric