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

[REBOL] Bug! - maybe not?? Re:

From: joel::neely::fedex::com at: 3-Oct-2000 7:06

[Al--Bri--xtra--co--nz] wrote:
> Bug! - 'insert can't handle a binary value in a block as it's 'value > argument
Note first that #{012345} is a three-byte sequence...
> >> head insert tail #{012345} #{0123} > == #{0123450123} ; Correct!
because #{0123} is a two-byte sequence, the result is the expected sequence of five bytes.
> >> head insert/only tail {012345} [{0123}] > == "0123450123" ; Correct!
because {012345} is a six-byte string, and {0123} is a four-byte string, the result is a ten-byte string. The content of the block is treated as a string.
> >> head insert/only tail #{012345} [#{0123}] > == #{012345237B303132337D} ; Wrong!
because #{012345} is a three-byte sequence, and the content of the block is treated as the seven-byte string "#{0123}"
> >> head insert tail {012345} [{0123}] > == "0123450123" ; Correct!
again, inserting a string into a string...
> >> head insert tail #{012345} [#{0123}] > == #{012345237B303132337D} ; Wrong!
again, converting the block to a string, then inserting that string as a sequence of bytes. Note that
>> any-string? #{1234}
== true So, my CONJECTURE is that the second argument to join and insert in these puzzling cases is simply being converted to a string, which is then stuffed into the appropriate place in the first argument. The result has the type of the first argument, and is therefore binary! in the puzzlers. It appears that join and insert like to have strings in some not-totally-obvious cases:
>> probe foo: join #{2d} ["(minus)" '+ #{28706c757329}]
#{2D286D696E7573292B237B3238373036433735373332397D} == #{2D286D696E7573292B237B3238373036433735373332397D}
>> to-string foo
== "-(minus)+#{28706C757329}"
>> probe foo: join none ["(minus)" '+ #{28706c757329}]
"none(minus)+#{28706C757329}" == "none(minus)+#{28706C757329}"
>> probe foo: join 0 ["(minus)" '+ #{28706c757329}]
"0(minus)+#{28706C757329}" == "0(minus)+#{28706C757329}"
>> probe foo: join #{2b} #{28706c757329}
#{2B28706C757329} == #{2B28706C757329}
>> to-string foo
== "+(plus)" However, this example highlights the urgency of having a complete specification of the REBOL language. This would allow us to a) read a specification ahead of time and avoid any unpleasant surprises in the behavior of our code, and b) (when surprised by our code) read the specification to learn whether our surprise is because REBOL didn't behave according to the specification (in which case we have discovered a bug in the implementation of REBOL) or because we didn't read the spec in advance (in which case we have discovered a bug in our mental model of REBOL). -jn-